From: Dessalines Date: Tue, 23 Nov 2021 19:30:16 +0000 (-0500) Subject: Fix API dupes query. #1878 X-Git-Url: http://these/git/%7B%60/feeds/front/static/%7BpictrsAvatarThumbnail%28this.state.siteRes.site.icon%29%7D?a=commitdiff_plain;h=f6b96370b8ac228ce63b3dad3e2e0ca962ad2ff5;p=lemmy.git Fix API dupes query. #1878 --- diff --git a/migrations/2021-11-22-135324_add_activity_ap_id_index/up.sql b/migrations/2021-11-22-135324_add_activity_ap_id_index/up.sql index fedd94f5..84530508 100644 --- a/migrations/2021-11-22-135324_add_activity_ap_id_index/up.sql +++ b/migrations/2021-11-22-135324_add_activity_ap_id_index/up.sql @@ -6,13 +6,13 @@ delete from activity where ap_id is null; alter table activity alter column ap_id set not null; -- Delete dupes, keeping the first one -delete -from activity -where id not in ( - select min(id) +delete from activity a using ( + select min(id) as id, ap_id from activity - group by ap_id -); + group by ap_id having count(*) > 1 +) b +where a.ap_id = b.ap_id +and a.id <> b.id; -- The index create unique index idx_activity_ap_id on activity(ap_id);