From a6163258bfd36053a3df545b8854f5ba21efe79a Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 12 Aug 2019 13:38:45 -0500 Subject: [PATCH] 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. --- app/models/post.rb | 2 +- app/models/tag.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index 9586f49fc..2addde42c 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -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 diff --git a/app/models/tag.rb b/app/models/tag.rb index b9e91fa55..d7e2960b7 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -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(" ")