Commit 60fe63c9 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'code_owners_n_plus_1' into 'master'

Memoize the code owner file

See merge request gitlab-org/gitlab!60980
parents 5972f9ad 59e73d35
...@@ -62,11 +62,7 @@ module Gitlab ...@@ -62,11 +62,7 @@ module Gitlab
end end
def code_owners_file def code_owners_file
if RequestStore.active? @code_owners_file ||= Gitlab::SafeRequestStore.fetch("project-#{@project.id}:code-owners:#{@ref}") do
RequestStore.fetch("project-#{@project.id}:code-owners:#{@ref}") do
load_code_owners_file
end
else
load_code_owners_file load_code_owners_file
end end
end end
......
...@@ -43,6 +43,12 @@ RSpec.describe Gitlab::CodeOwners::Loader do ...@@ -43,6 +43,12 @@ RSpec.describe Gitlab::CodeOwners::Loader do
expect(loader.entries).to contain_exactly(expected_entry) expect(loader.entries).to contain_exactly(expected_entry)
end end
it 'only calls out to the repository once' do
expect(project.repository).to receive(:code_owners_blob).once
2.times { loader.entries }
end
it 'loads all users that are members of the project into the entry' do it 'loads all users that are members of the project into the entry' do
expect(first_entry.users).to contain_exactly(owner_1, email_owner, documentation_owner) expect(first_entry.users).to contain_exactly(owner_1, email_owner, documentation_owner)
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