From 0e488ef70ab2608847423201e957693745f1e3b1 Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Tue, 11 Jul 2017 17:12:33 +0100 Subject: Clear issuable counter caches on update When an issuable's state changes, or one is created, we should clear the cache counts for a user's assigned issuables, and also the project-wide caches for this user type. --- app/finders/issuable_finder.rb | 16 +++++++++++++++- app/finders/issues_finder.rb | 10 ++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) (limited to 'app/finders') diff --git a/app/finders/issuable_finder.rb b/app/finders/issuable_finder.rb index d3010eff262..fc63e30c8fb 100644 --- a/app/finders/issuable_finder.rb +++ b/app/finders/issuable_finder.rb @@ -90,7 +90,13 @@ class IssuableFinder end def state_counter_cache_key - Digest::SHA1.hexdigest(state_counter_cache_key_components.flatten.join('-')) + cache_key(state_counter_cache_key_components) + end + + def clear_caches! + state_counter_cache_key_components_permutations.each do |components| + Rails.cache.delete(cache_key(components)) + end end def group @@ -424,4 +430,12 @@ class IssuableFinder ['issuables_count', klass.to_ability_name, opts.sort] end + + def state_counter_cache_key_components_permutations + [state_counter_cache_key_components] + end + + def cache_key(components) + Digest::SHA1.hexdigest(components.flatten.join('-')) + end end diff --git a/app/finders/issues_finder.rb b/app/finders/issues_finder.rb index 295a64ef5b8..0ec42a4e6eb 100644 --- a/app/finders/issues_finder.rb +++ b/app/finders/issues_finder.rb @@ -84,6 +84,16 @@ class IssuesFinder < IssuableFinder super + extra_components end + def state_counter_cache_key_components_permutations + # Ignore the last two, as we'll provide both options for them. + components = super.first[0..-3] + + [ + components + [false, true], + components + [true, false] + ] + end + def by_assignee(items) if assignee items.assigned_to(assignee) -- cgit v1.2.3