From d8749e7dfe84e5a6981bcf0dbff35512ea075572 Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 12 Aug 2019 13:38:45 -0500 Subject: [PATCH] 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. --- app/models/post.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/post.rb b/app/models/post.rb index 2addde42c..cdaec6f5c 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -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))