Fix Post.fast_count("pool:1537") == 0 (fixup 134958d1).

Fixup for a bug in 134958d1. `Post.fast_count("pool:1537")` still
returned zero because `Tag.is_simple_tag?` incorrectly parsed
"pool:1537" as a simple tag, so Post.fast_count still looked for it in
the tags table and found the empty "pool:1537" tag.
This commit is contained in:
evazion
2017-11-20 20:19:29 -06:00
parent 91147bba88
commit b3a9cd6c06
3 changed files with 50 additions and 2 deletions

View File

@@ -417,8 +417,27 @@ class Tag < ApplicationRecord
# 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)
is_single_tag?(query) && !is_metatag?(query) && !is_negated_tag?(query) && !is_optional_tag?(query) && !is_wildcard_tag?(query)
end
def is_single_tag?(query)
scan_query(query).size == 1
end
def is_metatag?(tag)
!!(tag =~ /\A(#{METATAGS}):(.+)\Z/i)
end
def is_negated_tag?(tag)
tag.starts_with?("-")
end
def is_optional_tag?(tag)
tag.starts_with?("~")
end
def is_wildcard_tag?(tag)
tag.include?("*")
end
def parse_query(query, options = {})