[deploy] Optimization: Cache Article cache_tagged_with Counts (#8712)
This commit is contained in:
parent
bfe663f407
commit
85f784a76c
1 changed files with 7 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue