summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2016-10-23 10:31:18 -0700
committerStan Hu <stanhu@gmail.com>2016-10-23 10:31:18 -0700
commit4ea1973f5971f9c72230779d28f228b5da1148af (patch)
tree85899024d97b0d5bc648e265684ec94e2d105d66
parenta98ad03ba18da0b1534f36dafafa9a1c644d0bf1 (diff)
downloadgitlab-ce-4ea1973f5971f9c72230779d28f228b5da1148af.tar.gz
Expire and build repository cache after project import
After a project import, there's a chance that the UI checks the branch count before the project has been imported. This change causes more of the keys to be flushed after an import and forces a rebuild of the repository cache. Closes #13518
-rw-r--r--CHANGELOG.md1
-rw-r--r--app/models/repository.rb18
-rw-r--r--spec/models/repository_spec.rb21
3 files changed, 20 insertions, 20 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b25431278bd..9999864662a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,7 @@ Please view this file on the master branch, on stable branches it's out of date.
## 8.13.1 (unreleased)
- Fix error in generating labels
+ - Expire and build repository cache after project import
## 8.13.0 (2016-10-22)
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 1b7f20a2134..c0460e3952f 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -419,6 +419,17 @@ class Repository
@exists = nil
end
+ # expire cache that doesn't depend on repository data (when expiring)
+ def expire_content_cache
+ expire_tags_cache
+ expire_tag_count_cache
+ expire_branches_cache
+ expire_branch_count_cache
+ expire_root_ref_cache
+ expire_emptiness_caches
+ expire_exists_cache
+ end
+
# Runs code after a repository has been created.
def after_create
expire_exists_cache
@@ -473,14 +484,13 @@ class Repository
end
def before_import
- expire_emptiness_caches
- expire_exists_cache
+ expire_content_cache
end
# Runs code after a repository has been forked/imported.
def after_import
- expire_emptiness_caches
- expire_exists_cache
+ expire_content_cache
+ build_cache
end
# Runs code after a new commit has been pushed.
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
index f977cf73673..187a1bf2d79 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -1146,28 +1146,17 @@ describe Repository, models: true do
end
describe '#before_import' do
- it 'flushes the emptiness cachess' do
- expect(repository).to receive(:expire_emptiness_caches)
-
- repository.before_import
- end
-
- it 'flushes the exists cache' do
- expect(repository).to receive(:expire_exists_cache)
+ it 'flushes the repository caches' do
+ expect(repository).to receive(:expire_content_cache)
repository.before_import
end
end
describe '#after_import' do
- it 'flushes the emptiness cachess' do
- expect(repository).to receive(:expire_emptiness_caches)
-
- repository.after_import
- end
-
- it 'flushes the exists cache' do
- expect(repository).to receive(:expire_exists_cache)
+ it 'flushes and builds the cache' do
+ expect(repository).to receive(:expire_content_cache)
+ expect(repository).to receive(:build_cache)
repository.after_import
end