search: don't fetch all records just to count them argh

Thanks, Scout. Found that in about two seconds.
This commit is contained in:
Peter Bhat Harkins 2019-05-08 18:32:07 -05:00
parent 5288928056
commit e23227f49e
1 changed files with 2 additions and 1 deletions

View File

@ -132,6 +132,7 @@ class Search
self.results = base.includes({ :taggings => :tag }, :user)
end
end
self.total_results = self.results.dup.count("stories.id")
case self.order
when "relevance"
@ -163,6 +164,7 @@ class Search
"comments.*, " +
"MATCH(comment) AGAINST('#{qwords}' IN BOOLEAN MODE) AS rel_comment"
).includes(:user, :story)
self.total_results = self.results.dup.count("comments.id")
case self.order
when "relevance"
@ -174,7 +176,6 @@ class Search
end
end
self.total_results = self.results.length
if self.page > self.page_count
self.page = self.page_count