]> Untitled Git - lemmy.git/commitdiff
Adding job to drop phantom ccnew indexes. Fixes #2431 (#2432)
authorDessalines <dessalines@users.noreply.github.com>
Wed, 7 Sep 2022 12:12:51 +0000 (08:12 -0400)
committerGitHub <noreply@github.com>
Wed, 7 Sep 2022 12:12:51 +0000 (12:12 +0000)
migrations/2022-09-07-113813_drop_ccnew_indexes_function/down.sql [new file with mode: 0644]
migrations/2022-09-07-113813_drop_ccnew_indexes_function/up.sql [new file with mode: 0644]
src/scheduled_tasks.rs

diff --git a/migrations/2022-09-07-113813_drop_ccnew_indexes_function/down.sql b/migrations/2022-09-07-113813_drop_ccnew_indexes_function/down.sql
new file mode 100644 (file)
index 0000000..3fc7778
--- /dev/null
@@ -0,0 +1 @@
+drop function drop_ccnew_indexes;
diff --git a/migrations/2022-09-07-113813_drop_ccnew_indexes_function/up.sql b/migrations/2022-09-07-113813_drop_ccnew_indexes_function/up.sql
new file mode 100644 (file)
index 0000000..2a861aa
--- /dev/null
@@ -0,0 +1,13 @@
+CREATE OR REPLACE FUNCTION drop_ccnew_indexes() RETURNS INTEGER AS $$
+DECLARE
+i RECORD;
+BEGIN
+  FOR i IN
+    (SELECT relname FROM pg_class WHERE relname like '%ccnew%')
+    LOOP
+      EXECUTE 'DROP INDEX ' || i.relname;
+    END LOOP;
+    RETURN 1;
+  END;
+$$ LANGUAGE plpgsql;
+
index 5b1ae419bc11f0918878fd08b368761011da0069..df54868fb5f8ce1e96a97a45b8621a32cf9a5935 100644 (file)
@@ -22,6 +22,7 @@ pub fn setup(pool: DbPool) -> Result<(), LemmyError> {
     active_counts(&conn);
     update_banned_when_expired(&conn);
     reindex_aggregates_tables(&conn, true);
+    drop_ccnew_indexes(&conn);
   });
 
   let conn = pool.get()?;
@@ -103,3 +104,13 @@ fn update_banned_when_expired(conn: &PgConnection) {
     .execute(conn)
     .expect("update banned when expires");
 }
+
+/// Drops the phantom CCNEW indexes created by postgres
+/// https://github.com/LemmyNet/lemmy/issues/2431
+fn drop_ccnew_indexes(conn: &PgConnection) {
+  info!("Dropping phantom ccnew indexes...");
+  let drop_stmt = "select drop_ccnew_indexes()";
+  sql_query(drop_stmt)
+    .execute(conn)
+    .expect("drop ccnew indexes");
+}