Skip to content

Commit

Permalink
Update post/thread/file deletion query scan parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Eggbertx committed Nov 23, 2024
1 parent 7c417e6 commit d41127a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions cmd/gochan/deleteposts.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

type delPost struct {
postID int
threadID int
opID int
isOP bool
filename string
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion sql/reset_views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d41127a

Please sign in to comment.