summaryrefslogtreecommitdiff
path: root/app/services/projects/count_service.rb
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2017-09-19 13:55:56 +0200
committerYorick Peterse <yorickpeterse@gmail.com>2017-09-19 17:16:45 +0200
commit57b96eb6db9b860991b035714e65ffd557327b6f (patch)
tree885c999406eeea7b8f73d6262db9a3043e86ad79 /app/services/projects/count_service.rb
parent404a56235f86a69b05991efcf4cc5d7c5f5c4567 (diff)
downloadgitlab-ce-57b96eb6db9b860991b035714e65ffd557327b6f.tar.gz
Fix refreshing of issues/MR count cachesfix-counts-caching
This ensures the open issues/MR count caches are refreshed properly when creating new issues or MRs. This MR also includes a change to the cache keys to ensure all caches are rebuilt on the fly. This particular problem was not caught in the test suite due to a null cache being used, resulting in all calls that would use a cache using the underlying data directly. In production the code would fail because a newly saved record returns an empty hash in #changes meaning checks such as `state_changed? || confidential_changed?` would return false for new rows, thus never updating the counters. Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/38061
Diffstat (limited to 'app/services/projects/count_service.rb')
-rw-r--r--app/services/projects/count_service.rb7
1 files changed, 6 insertions, 1 deletions
diff --git a/app/services/projects/count_service.rb b/app/services/projects/count_service.rb
index 5e633c37bf8..aa034315280 100644
--- a/app/services/projects/count_service.rb
+++ b/app/services/projects/count_service.rb
@@ -2,6 +2,11 @@ module Projects
# Base class for the various service classes that count project data (e.g.
# issues or forks).
class CountService
+ # The version of the cache format. This should be bumped whenever the
+ # underlying logic changes. This removes the need for explicitly flushing
+ # all caches.
+ VERSION = 1
+
def initialize(project)
@project = project
end
@@ -37,7 +42,7 @@ module Projects
end
def cache_key
- ['projects', @project.id, cache_key_name]
+ ['projects', 'count_service', VERSION, @project.id, cache_key_name]
end
end
end