Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding job to drop phantom ccnew indexes. Fixes #2431 #2432

Merged
merged 1 commit into from Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1 @@
drop function drop_ccnew_indexes;
13 changes: 13 additions & 0 deletions migrations/2022-09-07-113813_drop_ccnew_indexes_function/up.sql
@@ -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;

11 changes: 11 additions & 0 deletions src/scheduled_tasks.rs
Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think this needs to be run every hour, but probably doesnt make a difference.

});

let conn = pool.get()?;
Expand Down Expand Up @@ -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");
}