Commit d9885160 authored by Yorick Peterse's avatar Yorick Peterse

Merge branch '18709-branch-tag-collection-caching' into 'master'

Project dashboard appears to be loading tags on every request

See merge request !4996
parents 8a245b80 5fe85bc8
...@@ -22,6 +22,7 @@ v 8.10.0 (unreleased) ...@@ -22,6 +22,7 @@ v 8.10.0 (unreleased)
- PipelinesFinder uses git cache data - PipelinesFinder uses git cache data
- Check for conflicts with existing Project's wiki path when creating a new project. - Check for conflicts with existing Project's wiki path when creating a new project.
- Remove unused front-end variable -> default_issues_tracker - Remove unused front-end variable -> default_issues_tracker
- Better caching of git calls on ProjectsController#show.
- Add API endpoint for a group issues !4520 (mahcsig) - Add API endpoint for a group issues !4520 (mahcsig)
- Add Bugzilla integration !4930 (iamtjg) - Add Bugzilla integration !4930 (iamtjg)
- Allow [ci skip] to be in any case and allow [skip ci]. !4785 (simon_w) - Allow [ci skip] to be in any case and allow [skip ci]. !4785 (simon_w)
......
...@@ -246,24 +246,26 @@ class Repository ...@@ -246,24 +246,26 @@ class Repository
end end
end end
# Keys for data that can be affected for any commit push.
def cache_keys def cache_keys
%i(size branch_names tag_names branch_count tag_count commit_count %i(size commit_count
readme version contribution_guide changelog readme version contribution_guide changelog
license_blob license_key gitignore) license_blob license_key gitignore)
end end
# Keys for data on branch/tag operations.
def cache_keys_for_branches_and_tags
%i(branch_names tag_names branch_count tag_count)
end
def build_cache def build_cache
cache_keys.each do |key| (cache_keys + cache_keys_for_branches_and_tags).each do |key|
unless cache.exist?(key) unless cache.exist?(key)
send(key) send(key)
end end
end end
end end
def expire_gitignore
cache.expire(:gitignore)
end
def expire_tags_cache def expire_tags_cache
cache.expire(:tag_names) cache.expire(:tag_names)
@tags = nil @tags = nil
...@@ -286,8 +288,6 @@ class Repository ...@@ -286,8 +288,6 @@ class Repository
# This ensures this particular cache is flushed after the first commit to a # This ensures this particular cache is flushed after the first commit to a
# new repository. # new repository.
expire_emptiness_caches if empty? expire_emptiness_caches if empty?
expire_branch_count_cache
expire_tag_count_cache
end end
def expire_branch_cache(branch_name = nil) def expire_branch_cache(branch_name = nil)
......
...@@ -531,8 +531,6 @@ describe Repository, models: true do ...@@ -531,8 +531,6 @@ describe Repository, models: true do
describe '#expire_cache' do describe '#expire_cache' do
it 'expires all caches' do it 'expires all caches' do
expect(repository).to receive(:expire_branch_cache) expect(repository).to receive(:expire_branch_cache)
expect(repository).to receive(:expire_branch_count_cache)
expect(repository).to receive(:expire_tag_count_cache)
repository.expire_cache repository.expire_cache
end end
...@@ -1055,12 +1053,14 @@ describe Repository, models: true do ...@@ -1055,12 +1053,14 @@ describe Repository, models: true do
let(:cache) { repository.send(:cache) } let(:cache) { repository.send(:cache) }
it 'builds the caches if they do not already exist' do it 'builds the caches if they do not already exist' do
cache_keys = repository.cache_keys + repository.cache_keys_for_branches_and_tags
expect(cache).to receive(:exist?). expect(cache).to receive(:exist?).
exactly(repository.cache_keys.length). exactly(cache_keys.length).
times. times.
and_return(false) and_return(false)
repository.cache_keys.each do |key| cache_keys.each do |key|
expect(repository).to receive(key) expect(repository).to receive(key)
end end
...@@ -1068,12 +1068,14 @@ describe Repository, models: true do ...@@ -1068,12 +1068,14 @@ describe Repository, models: true do
end end
it 'does not build any caches that already exist' do it 'does not build any caches that already exist' do
cache_keys = repository.cache_keys + repository.cache_keys_for_branches_and_tags
expect(cache).to receive(:exist?). expect(cache).to receive(:exist?).
exactly(repository.cache_keys.length). exactly(cache_keys.length).
times. times.
and_return(true) and_return(true)
repository.cache_keys.each do |key| cache_keys.each do |key|
expect(repository).not_to receive(key) expect(repository).not_to receive(key)
end end
......
...@@ -40,6 +40,18 @@ describe GitPushService, services: true do ...@@ -40,6 +40,18 @@ describe GitPushService, services: true do
subject subject
end end
it 'flushes the branches cache' do
expect(project.repository).to receive(:expire_branches_cache)
subject
end
it 'flushes the branch count cache' do
expect(project.repository).to receive(:expire_branch_count_cache)
subject
end
end end
context 'existing branch' do context 'existing branch' do
...@@ -52,6 +64,18 @@ describe GitPushService, services: true do ...@@ -52,6 +64,18 @@ describe GitPushService, services: true do
subject subject
end end
it 'does not flush the branches cache' do
expect(project.repository).not_to receive(:expire_branches_cache)
subject
end
it 'does not flush the branch count cache' do
expect(project.repository).not_to receive(:expire_branch_count_cache)
subject
end
end end
context 'rm branch' do context 'rm branch' do
...@@ -66,6 +90,18 @@ describe GitPushService, services: true do ...@@ -66,6 +90,18 @@ describe GitPushService, services: true do
subject subject
end end
it 'flushes the branches cache' do
expect(project.repository).to receive(:expire_branches_cache)
subject
end
it 'flushes the branch count cache' do
expect(project.repository).to receive(:expire_branch_count_cache)
subject
end
it 'flushes general cached data' do it 'flushes general cached data' do
expect(project.repository).to receive(:expire_cache). expect(project.repository).to receive(:expire_cache).
with('master', newrev) with('master', newrev)
......
...@@ -11,6 +11,31 @@ describe GitTagPushService, services: true do ...@@ -11,6 +11,31 @@ describe GitTagPushService, services: true do
let(:newrev) { "8a2a6eb295bb170b34c24c76c49ed0e9b2eaf34b" } # gitlab-test: git rev-parse refs/tags/v1.1.0 let(:newrev) { "8a2a6eb295bb170b34c24c76c49ed0e9b2eaf34b" } # gitlab-test: git rev-parse refs/tags/v1.1.0
let(:ref) { 'refs/tags/v1.1.0' } let(:ref) { 'refs/tags/v1.1.0' }
describe "Push tags" do
subject do
service.execute
service
end
it 'flushes general cached data' do
expect(project.repository).to receive(:expire_cache)
subject
end
it 'flushes the tags cache' do
expect(project.repository).to receive(:expire_tags_cache)
subject
end
it 'flushes the tag count cache' do
expect(project.repository).to receive(:expire_tag_count_cache)
subject
end
end
describe "Git Tag Push Data" do describe "Git Tag Push Data" do
before do before do
service.execute service.execute
......
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