summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2016-02-09 17:19:12 +0000
committerDouwe Maan <douwe@gitlab.com>2016-02-09 17:19:12 +0000
commit883bbd61ca6f465a8fa15583bcefcafd83e40b02 (patch)
tree53f330b7e97af17a00c5f8d896128d95eae8523f /app/models
parentc8b6ec47ade1c8685c085310d650fb9af1c44521 (diff)
parent2ce0d06389c3eb7ac9a2b81f9fd339e7e56512bb (diff)
downloadgitlab-ce-883bbd61ca6f465a8fa15583bcefcafd83e40b02.tar.gz
Merge branch 'smarter-diverging-commit-cache-flushing' into 'master'
Smarter flushing of branch statistics caches This basically ensures we only flush caches of branches whenever we really have to. See commit c514f8b850219cd3e5526e73e1d00e6729e2b466 for the details. cc @joshfng @rspeicher See merge request !2769
Diffstat (limited to 'app/models')
-rw-r--r--app/models/repository.rb25
1 files changed, 14 insertions, 11 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 27bdbac3e52..0e17d2b669a 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -205,12 +205,6 @@ class Repository
readme version contribution_guide changelog license)
end
- def branch_cache_keys
- branches.map do |branch|
- :"diverging_commit_counts_#{branch.name}"
- end
- end
-
def build_cache
cache_keys.each do |key|
unless cache.exist?(key)
@@ -235,17 +229,26 @@ class Repository
@branches = nil
end
- def expire_cache
+ def expire_cache(branch_name = nil)
cache_keys.each do |key|
cache.expire(key)
end
- expire_branch_cache
+ expire_branch_cache(branch_name)
end
- def expire_branch_cache
- branches.each do |branch|
- cache.expire(:"diverging_commit_counts_#{branch.name}")
+ def expire_branch_cache(branch_name = nil)
+ # When we push to the root branch we have to flush the cache for all other
+ # branches as their statistics are based on the commits relative to the
+ # root branch.
+ if !branch_name || branch_name == root_ref
+ branches.each do |branch|
+ cache.expire(:"diverging_commit_counts_#{branch.name}")
+ end
+ # In case a commit is pushed to a non-root branch we only have to flush the
+ # cache for said branch.
+ else
+ cache.expire(:"diverging_commit_counts_#{branch_name}")
end
end