diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2017-01-16 02:40:44 +0000 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2017-01-16 02:40:44 +0000 |
commit | 701a8268f349bdf0e3cf8de704538794e503ee4b (patch) | |
tree | c5ed5c449c531f7da67901f0645c47d0a7ab810a | |
parent | 281f3fcfd542be720b690e1214ef4c64f787c5d8 (diff) | |
parent | d7cdcc51bd38f8b95d08656d4711f04fe844fa23 (diff) | |
download | gitlab-ce-701a8268f349bdf0e3cf8de704538794e503ee4b.tar.gz |
Merge branch 'pmq20/gitlab-ce-psvr/head/cache' into 'master'
Expire related caches after changing HEAD
See merge request !8584
-rw-r--r-- | app/models/project.rb | 2 | ||||
-rw-r--r-- | app/models/repository.rb | 5 | ||||
-rw-r--r-- | changelogs/unreleased/pmq20-gitlab-ce-psvr-head-cache.yml | 4 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 11 | ||||
-rw-r--r-- | spec/models/repository_spec.rb | 26 |
5 files changed, 32 insertions, 16 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index e85d3d3bc6c..1630975b0d3 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1032,7 +1032,7 @@ class Project < ActiveRecord::Base "refs/heads/#{branch}", force: true) repository.copy_gitattributes(branch) - repository.expire_avatar_cache + repository.after_change_head reload_default_branch end diff --git a/app/models/repository.rb b/app/models/repository.rb index 3266e9c75f0..43dba86e5ed 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -439,6 +439,11 @@ class Repository expire_content_cache end + # Runs code after the HEAD of a repository is changed. + def after_change_head + expire_method_caches(METHOD_CACHES_FOR_FILE_TYPES.keys) + end + # Runs code after a repository has been forked/imported. def after_import expire_content_cache diff --git a/changelogs/unreleased/pmq20-gitlab-ce-psvr-head-cache.yml b/changelogs/unreleased/pmq20-gitlab-ce-psvr-head-cache.yml new file mode 100644 index 00000000000..23230128dc9 --- /dev/null +++ b/changelogs/unreleased/pmq20-gitlab-ce-psvr-head-cache.yml @@ -0,0 +1,4 @@ +--- +title: Expire related caches after changing HEAD +merge_request: +author: Minqi Pan diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 32779eb92ef..e93a4e62244 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1545,11 +1545,13 @@ describe Project, models: true do end end - describe 'change_head' do + describe '#change_head' do let(:project) { create(:project) } - it 'calls the before_change_head method' do + it 'calls the before_change_head and after_change_head methods' do expect(project.repository).to receive(:before_change_head) + expect(project.repository).to receive(:after_change_head) + project.change_head(project.default_branch) end @@ -1565,11 +1567,6 @@ describe Project, models: true do project.change_head(project.default_branch) end - it 'expires the avatar cache' do - expect(project.repository).to receive(:expire_avatar_cache) - project.change_head(project.default_branch) - end - it 'reloads the default branch' do expect(project).to receive(:reload_default_branch) project.change_head(project.default_branch) diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index af7e89eae05..99ca53938c8 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -1150,6 +1150,24 @@ describe Repository, models: true do end end + describe '#after_change_head' do + it 'flushes the readme cache' do + expect(repository).to receive(:expire_method_caches).with([ + :readme, + :changelog, + :license, + :contributing, + :version, + :gitignore, + :koding, + :gitlab_ci, + :avatar + ]) + + repository.after_change_head + end + end + describe '#before_push_tag' do it 'flushes the cache' do expect(repository).to receive(:expire_statistics_caches) @@ -1513,14 +1531,6 @@ describe Repository, models: true do end end - describe '#expire_avatar_cache' do - it 'expires the cache' do - expect(repository).to receive(:expire_method_caches).with(%i(avatar)) - - repository.expire_avatar_cache - end - end - describe '#file_on_head' do context 'with a non-existing repository' do it 'returns nil' do |