From d4ef4ad752bf05758351bd0b8761566e40ab0e8e Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Tue, 30 Oct 2018 16:41:49 -0700 Subject: Reduce SQL queries needed to load open merge requests The SQL queries and memory allocation in MergeRequests::RefreshService is dominated by queries for Project and Route loads. On staging, the absence of an inverse relationship caused Rails to make over 1100 extraneous SQL queries for the www-gitlab-com repository. Relates to https://gitlab.com/gitlab-org/gitlab-ce/issues/49703 --- spec/models/project_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'spec/models/project_spec.rb') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index e66838edd1a..83b3f308ec3 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -88,6 +88,10 @@ describe Project do it { is_expected.to have_many(:project_deploy_tokens) } it { is_expected.to have_many(:deploy_tokens).through(:project_deploy_tokens) } + it 'has an inverse relationship with merge requests' do + expect(described_class.reflect_on_association(:merge_requests).has_inverse?).to eq(:target_project) + end + context 'after initialized' do it "has a project_feature" do expect(described_class.new.project_feature).to be_present -- cgit v1.2.1 From 733ae9492129e835f183902a97ee0886e2dbdc9b Mon Sep 17 00:00:00 2001 From: George Tsiolis Date: Tue, 30 Oct 2018 12:53:01 +0200 Subject: Fix typos in comments and specs --- spec/models/project_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/models/project_spec.rb') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 62a38c66d99..9f42621a23c 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -2746,7 +2746,7 @@ describe Project do .to raise_error(ActiveRecord::RecordNotSaved, error_message) end - it 'updates the project succesfully' do + it 'updates the project successfully' do merge_request = create(:merge_request, target_project: project, source_project: project) expect { project.append_or_update_attribute(:merge_requests, [merge_request]) } @@ -3314,7 +3314,7 @@ describe Project do end end - context 'when explicitely enabled' do + context 'when explicitly enabled' do context 'when domain is empty' do before do create(:project_auto_devops, project: project, domain: nil) -- cgit v1.2.1