media assets: optimize /media_assets?search[is_posted] query.
Followup to 093a808a3. Using a NOT EXISTS clause is much faster than the
`LEFT OUTER JOIN posts WHERE posts.id IS NULL` clause generated by
`.where.missing(:post)`.
This commit is contained in:
@@ -189,9 +189,11 @@ class MediaAsset < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
if params[:is_posted].to_s.truthy?
|
if params[:is_posted].to_s.truthy?
|
||||||
q = q.where.associated(:post)
|
#q = q.where.associated(:post)
|
||||||
|
q = q.where(Post.where("posts.md5 = media_assets.md5").arel.exists)
|
||||||
elsif params[:is_posted].to_s.falsy?
|
elsif params[:is_posted].to_s.falsy?
|
||||||
q = q.where.missing(:post)
|
#q = q.where.missing(:post)
|
||||||
|
q = q.where.not(Post.where("posts.md5 = media_assets.md5").arel.exists)
|
||||||
end
|
end
|
||||||
|
|
||||||
q.apply_default_order(params)
|
q.apply_default_order(params)
|
||||||
|
|||||||
Reference in New Issue
Block a user