Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/groups/count_service.rb')
-rw-r--r--app/services/groups/count_service.rb23
1 files changed, 18 insertions, 5 deletions
diff --git a/app/services/groups/count_service.rb b/app/services/groups/count_service.rb
index 2a15ae3bc57..735acddb025 100644
--- a/app/services/groups/count_service.rb
+++ b/app/services/groups/count_service.rb
@@ -19,13 +19,26 @@ module Groups
cached_count = Rails.cache.read(cache_key)
return cached_count unless cached_count.blank?
- refreshed_count = uncached_count
- update_cache_for_key(cache_key) { refreshed_count } if refreshed_count > CACHED_COUNT_THRESHOLD
- refreshed_count
+ refresh_cache_over_threshold
end
- def cache_key
- ['groups', "#{issuable_key}_count_service", VERSION, group.id, cache_key_name]
+ def refresh_cache_over_threshold(key = nil)
+ key ||= cache_key
+ new_count = uncached_count
+
+ if new_count > CACHED_COUNT_THRESHOLD
+ update_cache_for_key(key) { new_count }
+ else
+ delete_cache
+ end
+
+ new_count
+ end
+
+ def cache_key(key_name = nil)
+ key_name ||= cache_key_name
+
+ ['groups', "#{issuable_key}_count_service", VERSION, group.id, key_name]
end
private