Extract method to get the stats key in stats

This way we remove a bit of duplication and it'll be easier to change
the `stats_cache` method.
This commit is contained in:
Javi Martín
2024-04-08 14:53:13 +02:00
parent f30fa29994
commit 653848fc4e
3 changed files with 8 additions and 4 deletions

View File

@@ -192,7 +192,7 @@ class Budget::Stats
stats_cache(*stats_methods)
def stats_cache(key, &)
Rails.cache.fetch("budgets_stats/#{budget.id}/#{phases.join}/#{key}/#{version}", &)
def full_cache_key_for(key)
"budgets_stats/#{budget.id}/#{phases.join}/#{key}/#{version}"
end
end

View File

@@ -224,4 +224,8 @@ module Statisticable
I18n.t("stats.age_range", start: start, finish: finish)
end
end
def stats_cache(key, &)
Rails.cache.fetch(full_cache_key_for(key), &)
end
end

View File

@@ -121,7 +121,7 @@ class Poll::Stats
stats_cache(*stats_methods)
def stats_cache(key, &)
Rails.cache.fetch("polls_stats/#{poll.id}/#{key}/#{version}", &)
def full_cache_key_for(key)
"polls_stats/#{poll.id}/#{key}/#{version}"
end
end