limit ShareablesFromPerson queries to improve performance

This commit is contained in:
Fabián Rodríguez 2013-02-05 23:35:00 -02:00
parent 3f3b8f0d28
commit 703c52f74c

View file

@ -116,16 +116,12 @@ module EvilQuery
def make_relation! def make_relation!
return querents_posts if @person == @querent.person return querents_posts if @person == @querent.person
# persons_private_visibilities and persons_public_posts have no limit which is making shareable_ids gigantic.
# perhaps they should the arrays should be merged and sorted
# then the query at the bottom of this method can be paginated or something?
shareable_ids = contact.present? ? fetch_ids!(persons_private_visibilities, "share_visibilities.shareable_id") : [] shareable_ids = contact.present? ? fetch_ids!(persons_private_visibilities, "share_visibilities.shareable_id") : []
shareable_ids += fetch_ids!(persons_public_posts, table_name + ".id") shareable_ids += fetch_ids!(persons_public_posts, table_name + ".id")
@class.where(:id => shareable_ids, :pending => false). @class.where(:id => shareable_ids, :pending => false).
select('DISTINCT '+table_name+'.*'). select('DISTINCT ' + table_name + '.*').
order(table_name+".created_at DESC") order(table_name + ".created_at DESC")
end end
protected protected
@ -143,11 +139,11 @@ module EvilQuery
end end
def persons_private_visibilities def persons_private_visibilities
contact.share_visibilities.where(:hidden => false, :shareable_type => @class.to_s) contact.share_visibilities.where(:hidden => false, :shareable_type => @class.to_s).limit(15)
end end
def persons_public_posts def persons_public_posts
@person.send(table_name).where(:public => true).select(table_name+'.id') @person.send(table_name).where(:public => true).select(table_name + '.id').limit(15)
end end
end end
end end