Commit 701a8268 authored by Yorick Peterse's avatar Yorick Peterse

Merge branch 'pmq20/gitlab-ce-psvr/head/cache' into 'master'

Expire related caches after changing HEAD

See merge request !8584
parents 281f3fcf d7cdcc51
...@@ -1032,7 +1032,7 @@ class Project < ActiveRecord::Base ...@@ -1032,7 +1032,7 @@ class Project < ActiveRecord::Base
"refs/heads/#{branch}", "refs/heads/#{branch}",
force: true) force: true)
repository.copy_gitattributes(branch) repository.copy_gitattributes(branch)
repository.expire_avatar_cache repository.after_change_head
reload_default_branch reload_default_branch
end end
......
...@@ -439,6 +439,11 @@ class Repository ...@@ -439,6 +439,11 @@ class Repository
expire_content_cache expire_content_cache
end 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. # Runs code after a repository has been forked/imported.
def after_import def after_import
expire_content_cache expire_content_cache
......
---
title: Expire related caches after changing HEAD
merge_request:
author: Minqi Pan
...@@ -1545,11 +1545,13 @@ describe Project, models: true do ...@@ -1545,11 +1545,13 @@ describe Project, models: true do
end end
end end
describe 'change_head' do describe '#change_head' do
let(:project) { create(:project) } 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(:before_change_head)
expect(project.repository).to receive(:after_change_head)
project.change_head(project.default_branch) project.change_head(project.default_branch)
end end
...@@ -1565,11 +1567,6 @@ describe Project, models: true do ...@@ -1565,11 +1567,6 @@ describe Project, models: true do
project.change_head(project.default_branch) project.change_head(project.default_branch)
end 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 it 'reloads the default branch' do
expect(project).to receive(:reload_default_branch) expect(project).to receive(:reload_default_branch)
project.change_head(project.default_branch) project.change_head(project.default_branch)
......
...@@ -1150,6 +1150,24 @@ describe Repository, models: true do ...@@ -1150,6 +1150,24 @@ describe Repository, models: true do
end end
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 describe '#before_push_tag' do
it 'flushes the cache' do it 'flushes the cache' do
expect(repository).to receive(:expire_statistics_caches) expect(repository).to receive(:expire_statistics_caches)
...@@ -1513,14 +1531,6 @@ describe Repository, models: true do ...@@ -1513,14 +1531,6 @@ describe Repository, models: true do
end end
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 describe '#file_on_head' do
context 'with a non-existing repository' do context 'with a non-existing repository' do
it 'returns nil' do it 'returns nil' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment