diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e41f1adb8..8546c41b7 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -139,7 +139,7 @@ module ApplicationHelper def tag_colors(tag) Rails.cache.fetch("view-helper-#{tag}/tag_colors", expires_in: 5.hours) do - if found_tag = Tag.find_by_name(tag) + if found_tag = Tag.select(%i[bg_color_hex text_color_hex]).find_by_name(tag) { background: found_tag.bg_color_hex, color: found_tag.text_color_hex } else { background: "#d6d9e0", color: "#606570" } diff --git a/app/labor/flare_tag.rb b/app/labor/flare_tag.rb index 276c891d2..911f8aaec 100644 --- a/app/labor/flare_tag.rb +++ b/app/labor/flare_tag.rb @@ -19,7 +19,7 @@ class FlareTag def tag @tag ||= Rails.cache.fetch("article_flare_tag-#{article.id}-#{article.updated_at}", expires_in: 12.hours) do flare = FLARES.detect { |f| article.cached_tag_list_array.include?(f) } - flare && flare != except_tag ? Tag.find_by_name(flare) : nil + flare && flare != except_tag ? Tag.select(%i[name bg_color_hex text_color_hex]).find_by_name(flare) : nil end end diff --git a/app/labor/sticky_article_collection.rb b/app/labor/sticky_article_collection.rb index aa2dc6cf5..788880d48 100644 --- a/app/labor/sticky_article_collection.rb +++ b/app/labor/sticky_article_collection.rb @@ -3,7 +3,6 @@ class StickyArticleCollection def initialize(article, author) @article = article @author = author - @article_tags = article_tags @reaction_count_num = Rails.env.production? ? 15 : -1 @comment_count_num = Rails.env.production? ? 7 : -2 end @@ -18,16 +17,15 @@ class StickyArticleCollection end def suggested_stickies - (tag_articles + more_articles).sample(8) + (tag_articles.load + more_articles).sample(8) end def tag_articles - Article.tagged_with(article_tags, any: true). + @tag_articles ||= Article.tagged_with(article_tags, any: true). includes(:user). where("positive_reactions_count > ? OR comments_count > ?", reaction_count_num, comment_count_num). where(published: true). where.not(id: article.id, user_id: article.user_id). - limited_column_select. where("featured_number > ?", 5.days.ago.to_i). order("RANDOM()"). limit(8) @@ -39,7 +37,6 @@ class StickyArticleCollection Article.tagged_with(["career", "productivity", "discuss", "explainlikeimfive"], any: true). includes(:user). where("comments_count > ?", comment_count_num). - limited_column_select. where(published: true). where.not(id: article.id, user_id: article.user_id). where("featured_number > ?", 5.days.ago.to_i). @@ -48,8 +45,6 @@ class StickyArticleCollection end def article_tags - tags = article.cached_tag_list_array - tags.delete("discuss") - tags + @article_tags ||= article.cached_tag_list_array - ["discuss"] end end diff --git a/app/views/articles/_sticky_nav.html.erb b/app/views/articles/_sticky_nav.html.erb index 3c98df33b..ead59d06b 100644 --- a/app/views/articles/_sticky_nav.html.erb +++ b/app/views/articles/_sticky_nav.html.erb @@ -86,7 +86,7 @@ <% @sticky_collection = StickyArticleCollection.new(@article, @organization || @user) %> <% @sticky_articles = @sticky_collection.suggested_stickies %> <% @user_stickies = @sticky_collection.user_stickies %> - <% if @user_stickies && @user_stickies.any? %> + <% if @user_stickies.any? %> <% @user_stickies.each_with_index do |article, index| %>