Commit 8159b693 authored by Dmytro Zaporozhets (DZ)'s avatar Dmytro Zaporozhets (DZ)

Merge branch '325937-fix-notes-n-plus-1' into 'master'

Fix N+1 for notes (comments) scope [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!57460
parents 990fd614 8d66eae1
...@@ -135,6 +135,7 @@ class Note < ApplicationRecord ...@@ -135,6 +135,7 @@ class Note < ApplicationRecord
project: [:project_members, :namespace, { group: [:group_members] }]) project: [:project_members, :namespace, { group: [:group_members] }])
end end
scope :with_metadata, -> { includes(:system_note_metadata) } scope :with_metadata, -> { includes(:system_note_metadata) }
scope :with_web_entity_associations, -> { preload(:project, :author, :noteable) }
scope :for_note_or_capitalized_note, ->(text) { where(note: [text, text.capitalize]) } scope :for_note_or_capitalized_note, ->(text) { where(note: [text, text.capitalize]) }
scope :like_note_or_capitalized_note, ->(text) { where('(note LIKE ? OR note LIKE ?)', text, text.capitalize) } scope :like_note_or_capitalized_note, ->(text) { where('(note LIKE ? OR note LIKE ?)', text, text.capitalize) }
......
...@@ -9,7 +9,8 @@ class SearchServicePresenter < Gitlab::View::Presenter::Delegated ...@@ -9,7 +9,8 @@ class SearchServicePresenter < Gitlab::View::Presenter::Delegated
projects: :with_web_entity_associations, projects: :with_web_entity_associations,
issues: :with_web_entity_associations, issues: :with_web_entity_associations,
merge_requests: :with_web_entity_associations, merge_requests: :with_web_entity_associations,
epics: :with_web_entity_associations epics: :with_web_entity_associations,
notes: :with_web_entity_associations
}.freeze }.freeze
SORT_ENABLED_SCOPES = %w(issues merge_requests).freeze SORT_ENABLED_SCOPES = %w(issues merge_requests).freeze
......
---
title: Fix N+1 for searching notes (comments) scope
merge_request: 57460
author:
type: performance
...@@ -70,6 +70,16 @@ RSpec.describe SearchController, type: :request do ...@@ -70,6 +70,16 @@ RSpec.describe SearchController, type: :request do
it_behaves_like 'an efficient database result' it_behaves_like 'an efficient database result'
end end
context 'for notes scope' do
let(:creation_traits) { [:on_commit] }
let(:object) { :note }
let(:creation_args) { { project: project } }
let(:params) { { search: '*', scope: 'notes' } }
let(:threshold) { 0 }
it_behaves_like 'an efficient database result'
end
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