Fix #3390: Searching certain metatags results in an empty paginator
Fixes Post#get_count_from_cache to only lookup the count in the tags table when the search is for a single "simple" tag. Check memcache when the search is not a simple tag: * multi-tag searches (touhou rating:s) * single metatag searches (rating:s, source:"foo bar") * negated tags (-touhou) * wildcard tags (*touhou*) * or searches (~touhou)
This commit is contained in:
@@ -1218,14 +1218,14 @@ class Post < ApplicationRecord
|
||||
end
|
||||
|
||||
def get_count_from_cache(tags)
|
||||
count = Cache.get(count_cache_key(tags)) # this will only have a value for multi-tag searches
|
||||
|
||||
if count.nil? && !tags.include?(" ")
|
||||
if Tag.is_simple_tag?(tags)
|
||||
count = select_value_sql("SELECT post_count FROM tags WHERE name = ?", tags.to_s)
|
||||
# set_count_in_cache(tags, count.to_i) if count
|
||||
else
|
||||
# this will only have a value for multi-tag searches or single metatag searches
|
||||
count = Cache.get(count_cache_key(tags))
|
||||
end
|
||||
|
||||
count ? count.to_i : nil
|
||||
count.try(:to_i)
|
||||
end
|
||||
|
||||
def set_count_in_cache(tags, count, expiry = nil)
|
||||
|
||||
@@ -415,6 +415,12 @@ class Tag < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
# true if query is a single "simple" tag (not a metatag, negated tag, or wildcard tag).
|
||||
def is_simple_tag?(query)
|
||||
q = parse_query(query)
|
||||
(scan_query(query).size == 1) && (q[:tags][:related].size == 1)
|
||||
end
|
||||
|
||||
def parse_query(query, options = {})
|
||||
q = {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user