[deploy] Optimization: Cache Article cache_tagged_with Counts (#8712)

This commit is contained in:
Molly Struve 2020-06-16 12:26:52 -05:00 committed by GitHub
parent bfe663f407
commit 85f784a76c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -137,7 +137,7 @@ class StoriesController < ApplicationController
@num_published_articles = if @tag_model.requires_approval?
Article.published.cached_tagged_by_approval_with(@tag).size
else
Article.published.cached_tagged_with(@tag).where("score > 2").size
cached_tagged_count
end
@number_of_articles = user_signed_in? ? 5 : SIGNED_OUT_RECORD_COUNT
@stories = Articles::Feed.new(number_of_articles: @number_of_articles, tag: @tag, page: @page).
@ -487,4 +487,10 @@ 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 > 2").size
end
end
end