Commit 6bfecb09 authored by Robert May's avatar Robert May

Slight refactor of the repository changes

parent 003e7093
...@@ -915,13 +915,13 @@ class Repository ...@@ -915,13 +915,13 @@ class Repository
end end
def merged_branch_names(branch_names = []) def merged_branch_names(branch_names = [])
if branch_names.empty? || Feature.disabled?(:merged_branch_names_redis_caching)
# Currently we should skip caching if requesting all branch names # Currently we should skip caching if requesting all branch names
# This is only used in a few places, notably app/services/branches/delete_merged_service.rb, # This is only used in a few places, notably app/services/branches/delete_merged_service.rb,
# and it could potentially result in a very large cache/performance issues with the current # and it could potentially result in a very large cache/performance issues with the current
# implementation. # implementation.
raw_repository.merged_branch_names(branch_names) skip_cache = branch_names.empty? || Feature.disabled?(:merged_branch_names_redis_caching)
else return raw_repository.merged_branch_names(branch_names) if skip_cache
cached_branch_names = cache.read(:merged_branch_names) cached_branch_names = cache.read(:merged_branch_names)
merged_branch_names_hash = cached_branch_names.present? ? JSON.parse(cached_branch_names) : {} merged_branch_names_hash = cached_branch_names.present? ? JSON.parse(cached_branch_names) : {}
missing_branch_names = branch_names.select { |bn| !merged_branch_names_hash.key?(bn) } missing_branch_names = branch_names.select { |bn| !merged_branch_names_hash.key?(bn) }
...@@ -947,7 +947,6 @@ class Repository ...@@ -947,7 +947,6 @@ class Repository
Set.new(merged_branch_names_hash.select { |k, v| v.to_s == "true" }.keys) Set.new(merged_branch_names_hash.select { |k, v| v.to_s == "true" }.keys)
end end
end
def merge_base(*commits_or_ids) def merge_base(*commits_or_ids)
commit_ids = commits_or_ids.map do |commit_or_id| commit_ids = commits_or_ids.map do |commit_or_id|
......
...@@ -537,12 +537,16 @@ describe Repository do ...@@ -537,12 +537,16 @@ describe Repository do
it { is_expected.to eq(already_merged) } it { is_expected.to eq(already_merged) }
describe "cache values" do describe "cache values" do
after do it "writes the values to redis" do
expect(cache).to receive(:write).with(cache_key, merge_state_hash.to_json, expires_in: 10.minutes)
subject subject
end end
it "writes the values to redis" do it "matches the supplied hash" do
expect(cache).to receive(:write).with(cache_key, merge_state_hash.to_json, expires_in: 10.minutes) subject
expect(JSON.parse(cache.read(cache_key))).to eq(merge_state_hash)
end end
end end
end end
......
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