Add table to store stats versions

We need a way to manually expire the cache for a budget or poll without
expiring the cache of every budget or poll.

Using the `updated_at` column would be dangerous because most of the
times we update a budget or a poll, we don't need to regenerate their
stats.

We've considered adding a `stats_updated_at` column to each of these
tables. However, in that case we would also need to add a similar column
in the future to every process type whose stats we want to generate.
This commit is contained in:
Javi Martín
2019-04-08 16:22:23 +02:00
parent 9335c51cfc
commit 7c0e499eee
11 changed files with 79 additions and 2 deletions

View File

@@ -107,7 +107,7 @@ class Poll::Stats
stats_cache :participants, :voters, :recounts
def stats_cache(key, &block)
Rails.cache.fetch("polls_stats/#{poll.id}/#{key}/v12", &block)
Rails.cache.fetch("polls_stats/#{poll.id}/#{key}/#{version}", &block)
end
end