]> Untitled Git - lemmy.git/commitdiff
Merge pull request #1951 from LemmyNet/fix_ap_id_dupes_query
authorDessalines <dessalines@users.noreply.github.com>
Tue, 23 Nov 2021 19:37:58 +0000 (14:37 -0500)
committerGitHub <noreply@github.com>
Tue, 23 Nov 2021 19:37:58 +0000 (14:37 -0500)
Fix API dupes query. #1878

migrations/2021-11-22-135324_add_activity_ap_id_index/up.sql

index fedd94f5e4182f1a62ed5482496c7b9997a983d3..84530508e94d3f131ddbbc23d98ca64f449cc93e 100644 (file)
@@ -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);