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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user