From d41127a1dfb033ebe7a82f3935a73946637bdcc2 Mon Sep 17 00:00:00 2001 From: Eggbertx Date: Sat, 23 Nov 2024 11:27:11 -0800 Subject: [PATCH] Update post/thread/file deletion query scan parameters --- cmd/gochan/deleteposts.go | 9 +++++---- sql/reset_views.sql | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cmd/gochan/deleteposts.go b/cmd/gochan/deleteposts.go index e59ecfd7..842e74ca 100644 --- a/cmd/gochan/deleteposts.go +++ b/cmd/gochan/deleteposts.go @@ -24,6 +24,7 @@ import ( type delPost struct { postID int + threadID int opID int isOP bool filename string @@ -117,12 +118,12 @@ func getAllPostsToDelete(postIDs []any, fileOnly bool) ([]delPost, []any, error) params := postIDs if fileOnly { // only deleting this post's file, not subfiles if it's an OP - query = "SELECT * FROM DBPREFIXv_posts_to_delete_file_only WHERE p.id IN " + setPart + query = "SELECT * FROM DBPREFIXv_posts_to_delete_file_only WHERE postid IN " + setPart } else { // deleting everything, including subfiles params = append(params, postIDs...) - query = "SELECT * FROM DBPREFIXv_posts_to_delete WHERE p.id IN " + setPart + - ` OR p.thread_id IN (SELECT thread_id from DBPREFIXposts op WHERE op.id IN ` + setPart + ` AND is_top_post)` + query = "SELECT * FROM DBPREFIXv_posts_to_delete WHERE postid IN " + setPart + + ` OR thread_id IN (SELECT thread_id from DBPREFIXposts op WHERE opid IN ` + setPart + ` AND is_top_post)` } rows, err := gcsql.QuerySQL(query, params...) if err != nil { @@ -132,7 +133,7 @@ func getAllPostsToDelete(postIDs []any, fileOnly bool) ([]delPost, []any, error) var postIDsAny []any for rows.Next() { var post delPost - if err = rows.Scan(&post.postID, &post.opID, &post.isOP, &post.filename, &post.boardDir); err != nil { + if err = rows.Scan(&post.postID, &post.threadID, &post.opID, &post.isOP, &post.filename, &post.boardDir); err != nil { rows.Close() return nil, nil, err } diff --git a/sql/reset_views.sql b/sql/reset_views.sql index 51048f30..6495cf3b 100644 --- a/sql/reset_views.sql +++ b/sql/reset_views.sql @@ -42,7 +42,7 @@ INNER JOIN DBPREFIXv_top_post_thread_ids op ON op.thread_id = p.thread_id WHERE p.is_deleted = FALSE; CREATE VIEW DBPREFIXv_posts_to_delete AS -SELECT p.id AS postid, ( +SELECT p.id AS postid, thread_id, ( SELECT op.id AS opid FROM DBPREFIXposts op WHERE op.thread_id = p.thread_id AND is_top_post LIMIT 1 ) as opid, is_top_post, COALESCE(filename, '') AS filename, dir