FIX: Don't use joins to filter (#24904)

Posts may have multiple uploads/upload references.
This commit is contained in:
Daniel Waterworth 2024-01-10 23:11:29 -06:00 committed by GitHub
parent cabbc3899f
commit 30bea5c7c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -89,17 +89,17 @@ class TopicUploadSecurityManager
private private
def posts_owning_uploads 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 end
def posts_with_unowned_uploads def posts_with_unowned_uploads
Post Post.where(
.where(topic_id: @topic.id) topic_id: @topic.id,
.joins( id:
"INNER JOIN upload_references ON upload_references.target_type = 'Post' AND upload_references.target_id = posts.id", UploadReference.where(
) target_type: "Post",
.joins("INNER JOIN uploads ON upload_references.upload_id = uploads.id") upload: Upload.where(access_control_post_id: nil),
.where("uploads.access_control_post_id IS NULL") ).select(:target_id),
.includes(:uploads) ).includes(:uploads)
end end
end end