Skip to content
Snippets Groups Projects
Commit bcd89dcd authored by Grzegorz Bizon's avatar Grzegorz Bizon
Browse files

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
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -331,6 +331,7 @@ class Repository
return unless empty?
 
expire_method_caches(%i(has_visible_content?))
raw_repository.expire_has_local_branches_cache
end
 
def lookup_cache
Loading
Loading
---
title: Memoize Git::Repository#has_visible_content?
merge_request:
author:
type: performance
Loading
Loading
@@ -9,6 +9,7 @@ module Gitlab
include Gitlab::Git::RepositoryMirroring
include Gitlab::Git::Popen
include Gitlab::EncodingHelper
include Gitlab::Utils::StrongMemoize
 
ALLOWED_OBJECT_DIRECTORIES_VARIABLES = %w[
GIT_OBJECT_DIRECTORY
Loading
Loading
@@ -231,13 +232,13 @@ module Gitlab
end
end
 
def expire_has_local_branches_cache
clear_memoization(:has_local_branches)
end
def 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
strong_memoize(:has_local_branches) do
uncached_has_local_branches?
end
end
 
Loading
Loading
@@ -1559,6 +1560,16 @@ module Gitlab
 
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)
if shell
shell_write_ref(ref_path, ref, old_ref)
Loading
Loading
Loading
Loading
@@ -470,9 +470,20 @@ describe Gitlab::Git::Repository, seed_helper: true do
FileUtils.rm_rf(heads_dir)
FileUtils.mkdir_p(heads_dir)
 
repository.expire_has_local_branches_cache
expect(repository.has_local_branches?).to eq(false)
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
 
context 'with gitaly' do
Loading
Loading
Loading
Loading
@@ -1437,6 +1437,12 @@ describe Repository do
 
repository.expire_emptiness_caches
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
 
describe 'skip_merges option' do
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment