Skip to content

Commit

Permalink
Add more aggressive caching to the descriptions controller
Browse files Browse the repository at this point in the history
  • Loading branch information
ujh committed Jan 5, 2025
1 parent f44989b commit 826b876
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions app/controllers/descriptions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,25 @@ def my_missing
private

def brands_without_descriptions_ids
BrandCluster.without_description.pluck(:id)
Rails
.cache
.fetch(
"DescriptionsController#brands_without_descriptions_ids",
expires_in: 10.minutes
) { BrandCluster.without_description.pluck(:id) }
end

def my_brands_without_descriptions_ids
BrandCluster.without_description_of_user(current_user).pluck(:id)
end

def clusters_without_descriptions_ids
clusters_hash = MacroCluster.without_description.pluck(:id).hash
key =
"DescriptionsController#clusters_without_descriptions_ids-#{clusters_hash}"
Rails
.cache
.fetch(key, expires_in: 1.hour) do
.fetch(
"DescriptionsController#clusters_without_descriptions_ids",
expires_in: 10.minutes
) do
MacroCluster
.without_description
.joins(micro_clusters: :collected_inks)
Expand Down

0 comments on commit 826b876

Please sign in to comment.