diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index f89cb9901..0a669ff38 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -131,12 +131,13 @@ class StoriesController < ApplicationController end @num_published_articles = if @tag_model.requires_approval? - Article.published.cached_tagged_by_approval_with(@tag).size + @tag_model.articles.published.where(approved: true).count elsif SiteConfig.feed_strategy == "basic" - Article.published.cached_tagged_with(@tag) - .where("score >= ?", SiteConfig.tag_feed_minimum_score).size + tagged_count else - cached_tagged_count + Rails.cache.fetch("article-cached-tagged-count-#{@tag}", expires_in: 2.hours) do + tagged_count + end end @number_of_articles = user_signed_in? ? 5 : SIGNED_OUT_RECORD_COUNT @stories = Articles::Feeds::LargeForemExperimental @@ -484,9 +485,7 @@ class StoriesController < ApplicationController params[:sort_direction] == "desc" ? :newest : :oldest end - def cached_tagged_count - Rails.cache.fetch("article-cached-tagged-count-#{@tag}", expires_in: 2.hours) do - Article.published.cached_tagged_with(@tag).where("score >= ?", SiteConfig.tag_feed_minimum_score).size - end + def tagged_count + @tag_model.articles.published.where("score >= ?", SiteConfig.tag_feed_minimum_score).count end end diff --git a/spec/initializers/rack/attack_spec.rb b/spec/initializers/rack/attack_spec.rb index 93c8a4f00..d02eb099f 100644 --- a/spec/initializers/rack/attack_spec.rb +++ b/spec/initializers/rack/attack_spec.rb @@ -132,7 +132,7 @@ describe Rack::Attack, type: :request, throttle: true do # rubocop:disable RSpec/AnyInstance, RSpec/ExampleLength it "throttles viewing tags" do - allow_any_instance_of(StoriesController).to receive(:cached_tagged_count).and_return(0) + allow_any_instance_of(StoriesController).to receive(:tagged_count).and_return(0) allow_any_instance_of(StoriesController).to receive(:stories_by_timeframe).and_return(Article.none) allow_any_instance_of(Articles::Feeds::LargeForemExperimental).to receive( :published_articles_by_tag,