search: save a query in fast_count (#4120).

During single-tag searches we look up the tag once in Post.fast_count
and later on when rendering the wiki excerpt. Doing a raw query here
meant that Rails couldn't cache the query, so it got ran again when
rendering the excerpt.
This commit is contained in:
evazion
2019-08-12 13:38:45 -05:00
parent 43e8a8a01b
commit d8749e7dfe

View File

@@ -1177,7 +1177,7 @@ class Post < ApplicationRecord
def get_count_from_cache(tags)
if Tag.is_simple_tag?(tags)
count = select_value_sql("SELECT post_count FROM tags WHERE name = ?", tags.to_s)
count = Tag.find_by(name: tags).try(:post_count)
else
# this will only have a value for multi-tag searches or single metatag searches
count = Cache.get(count_cache_key(tags))