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
end
def code_owners_file
if RequestStore.active?
RequestStore.fetch("project-#{@project.id}:code-owners:#{@ref}") do
load_code_owners_file
end
else
@code_owners_file ||= Gitlab::SafeRequestStore.fetch("project-#{@project.id}:code-owners:#{@ref}") do
load_code_owners_file
end
end
......
......@@ -43,6 +43,12 @@ RSpec.describe Gitlab::CodeOwners::Loader do
expect(loader.entries).to contain_exactly(expected_entry)
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
expect(first_entry.users).to contain_exactly(owner_1, email_owner, documentation_owner)
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