Post.fast_count: skip alias normalization.

Post.fast_count calls Tag.normalize_query to normalize the tag string
used for the pfc cache key. This slightly improves cache sharing at the
expense of an extra query during tag searches. The extra query isn't
worth it.
This commit is contained in:
evazion
2019-08-12 13:38:45 -05:00
parent 30a378865e
commit a6163258bf
2 changed files with 3 additions and 3 deletions

View File

@@ -1111,7 +1111,7 @@ class Post < ApplicationRecord
tags = tags.to_s
tags += " rating:s" if CurrentUser.safe_mode?
tags += " -status:deleted" if CurrentUser.hide_deleted_posts? && !Tag.has_metatag?(tags, "status", "-status")
tags = Tag.normalize_query(tags)
tags = Tag.normalize_query(tags, normalize_aliases: false)
# optimize some cases. these are just estimates but at these
# quantities being off by a few hundred doesn't matter much

View File

@@ -272,10 +272,10 @@ class Tag < ApplicationRecord
query.to_s.gsub(/\u3000/, " ").strip
end
def normalize_query(query, sort: true)
def normalize_query(query, normalize_aliases: true, sort: true)
tags = Tag.scan_query(query.to_s)
tags = tags.map { |t| Tag.normalize_name(t) }
tags = TagAlias.to_aliased(tags)
tags = TagAlias.to_aliased(tags) if normalize_aliases
tags = tags.sort if sort
tags = tags.uniq
tags.join(" ")