Skip to content

Commit

Permalink
FIX: Don't use joins to filter (discourse#24904)
Browse files Browse the repository at this point in the history
Posts may have multiple uploads/upload references.
  • Loading branch information
danielwaterworth authored Jan 11, 2024
1 parent cabbc38 commit 30bea5c
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/topic_upload_security_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,17 @@ def run
private

def posts_owning_uploads
Post.where(topic_id: @topic.id).joins("INNER JOIN uploads ON access_control_post_id = posts.id")
Post.where(topic_id: @topic.id, id: Upload.select(:access_control_post_id))
end

def posts_with_unowned_uploads
Post
.where(topic_id: @topic.id)
.joins(
"INNER JOIN upload_references ON upload_references.target_type = 'Post' AND upload_references.target_id = posts.id",
)
.joins("INNER JOIN uploads ON upload_references.upload_id = uploads.id")
.where("uploads.access_control_post_id IS NULL")
.includes(:uploads)
Post.where(
topic_id: @topic.id,
id:
UploadReference.where(
target_type: "Post",
upload: Upload.where(access_control_post_id: nil),
).select(:target_id),
).includes(:uploads)
end
end

0 comments on commit 30bea5c

Please sign in to comment.