From b1f2096d721a5dc93a155e162fda5ef29099aee2 Mon Sep 17 00:00:00 2001 From: evazion Date: Sun, 30 Sep 2018 13:21:12 -0500 Subject: [PATCH] TagSetPresenter: refactor *_tag_list_html to avoid memcache calls. Refactor the tag set presenter to get both the tag categories and the tag counts in the same call to the database, instead of getting the counts from the db and the categories from memcache. --- app/models/tag.rb | 4 -- app/presenters/tag_set_presenter.rb | 79 ++++++++++++++--------------- 2 files changed, 38 insertions(+), 45 deletions(-) diff --git a/app/models/tag.rb b/app/models/tag.rb index 2d3ad47c3..135bd3c46 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -56,10 +56,6 @@ class Tag < ApplicationRecord extend ActiveSupport::Concern module ClassMethods - def counts_for(tag_names) - select_all_sql("SELECT name, post_count FROM tags WHERE name IN (?)", tag_names) - end - def highest_post_count Cache.get("highest-post-count", 4.hours) do select("post_count").order("post_count DESC").first.post_count diff --git a/app/presenters/tag_set_presenter.rb b/app/presenters/tag_set_presenter.rb index b5cadc582..e8b499010 100644 --- a/app/presenters/tag_set_presenter.rb +++ b/app/presenters/tag_set_presenter.rb @@ -5,7 +5,8 @@ =end class TagSetPresenter < Presenter - attr_reader :tag_names, :tags + extend Memoist + attr_reader :tag_names def initialize(tag_names) @tag_names = tag_names @@ -13,9 +14,10 @@ class TagSetPresenter < Presenter def tag_list_html(current_query: "", show_extra_links: false, name_only: false) html = "" - if tag_names.present? + + if ordered_tags.present? html << '" @@ -28,7 +30,8 @@ class TagSetPresenter < Presenter html = "" category_list.each do |category| - typetags = typed_tags(category) + typetags = ordered_tags.select { |tag| tag.category == Tag.categories.value_for(category) } + if typetags.any? html << TagCategory.header_mapping[category] if headers html << %{