Commit bcd89dcd authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'sh-memoize-repository-empty' into 'master'

Memoize Git::Repository#has_visible_content?

See merge request gitlab-org/gitlab-ce!18383
parents 2f3e74d8 cf955af1
...@@ -331,6 +331,7 @@ class Repository ...@@ -331,6 +331,7 @@ class Repository
return unless empty? return unless empty?
expire_method_caches(%i(has_visible_content?)) expire_method_caches(%i(has_visible_content?))
raw_repository.expire_has_local_branches_cache
end end
def lookup_cache def lookup_cache
......
---
title: Memoize Git::Repository#has_visible_content?
merge_request:
author:
type: performance
...@@ -9,6 +9,7 @@ module Gitlab ...@@ -9,6 +9,7 @@ module Gitlab
include Gitlab::Git::RepositoryMirroring include Gitlab::Git::RepositoryMirroring
include Gitlab::Git::Popen include Gitlab::Git::Popen
include Gitlab::EncodingHelper include Gitlab::EncodingHelper
include Gitlab::Utils::StrongMemoize
ALLOWED_OBJECT_DIRECTORIES_VARIABLES = %w[ ALLOWED_OBJECT_DIRECTORIES_VARIABLES = %w[
GIT_OBJECT_DIRECTORY GIT_OBJECT_DIRECTORY
...@@ -231,13 +232,13 @@ module Gitlab ...@@ -231,13 +232,13 @@ module Gitlab
end end
end end
def has_local_branches? def expire_has_local_branches_cache
gitaly_migrate(:has_local_branches, status: Gitlab::GitalyClient::MigrationStatus::OPT_OUT) do |is_enabled| clear_memoization(:has_local_branches)
if is_enabled
gitaly_repository_client.has_local_branches?
else
has_local_branches_rugged?
end end
def has_local_branches?
strong_memoize(:has_local_branches) do
uncached_has_local_branches?
end end
end end
...@@ -1559,6 +1560,16 @@ module Gitlab ...@@ -1559,6 +1560,16 @@ module Gitlab
private private
def uncached_has_local_branches?
gitaly_migrate(:has_local_branches, status: Gitlab::GitalyClient::MigrationStatus::OPT_OUT) do |is_enabled|
if is_enabled
gitaly_repository_client.has_local_branches?
else
has_local_branches_rugged?
end
end
end
def local_write_ref(ref_path, ref, old_ref: nil, shell: true) def local_write_ref(ref_path, ref, old_ref: nil, shell: true)
if shell if shell
shell_write_ref(ref_path, ref, old_ref) shell_write_ref(ref_path, ref, old_ref)
......
...@@ -470,9 +470,20 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -470,9 +470,20 @@ describe Gitlab::Git::Repository, seed_helper: true do
FileUtils.rm_rf(heads_dir) FileUtils.rm_rf(heads_dir)
FileUtils.mkdir_p(heads_dir) FileUtils.mkdir_p(heads_dir)
repository.expire_has_local_branches_cache
expect(repository.has_local_branches?).to eq(false) expect(repository.has_local_branches?).to eq(false)
end end
end end
context 'memoizes the value' do
it 'returns true' do
expect(repository).to receive(:uncached_has_local_branches?).once.and_call_original
2.times do
expect(repository.has_local_branches?).to eq(true)
end
end
end
end end
context 'with gitaly' do context 'with gitaly' do
......
...@@ -1437,6 +1437,12 @@ describe Repository do ...@@ -1437,6 +1437,12 @@ describe Repository do
repository.expire_emptiness_caches repository.expire_emptiness_caches
end end
it 'expires the memoized repository cache' do
allow(repository.raw_repository).to receive(:expire_has_local_branches_cache).and_call_original
repository.expire_emptiness_caches
end
end end
describe 'skip_merges option' do describe 'skip_merges option' 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