Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
8d66eae1
Commit
8d66eae1
authored
Mar 25, 2021
by
Dmitry Gruzd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix N+1 for searching notes (comments) scope
parent
0038d3a2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
1 deletion
+18
-1
app/models/note.rb
app/models/note.rb
+1
-0
app/presenters/search_service_presenter.rb
app/presenters/search_service_presenter.rb
+2
-1
changelogs/unreleased/325937-fix-notes-n-plus-1.yml
changelogs/unreleased/325937-fix-notes-n-plus-1.yml
+5
-0
ee/spec/requests/search_controller_spec.rb
ee/spec/requests/search_controller_spec.rb
+10
-0
No files found.
app/models/note.rb
View file @
8d66eae1
...
...
@@ -135,6 +135,7 @@ class Note < ApplicationRecord
project:
[
:project_members
,
:namespace
,
{
group:
[
:group_members
]
}])
end
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
:like_note_or_capitalized_note
,
->
(
text
)
{
where
(
'(note LIKE ? OR note LIKE ?)'
,
text
,
text
.
capitalize
)
}
...
...
app/presenters/search_service_presenter.rb
View file @
8d66eae1
...
...
@@ -9,7 +9,8 @@ class SearchServicePresenter < Gitlab::View::Presenter::Delegated
projects: :with_web_entity_associations
,
issues: :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
SORT_ENABLED_SCOPES
=
%w(issues merge_requests)
.
freeze
...
...
changelogs/unreleased/325937-fix-notes-n-plus-1.yml
0 → 100644
View file @
8d66eae1
---
title
:
Fix N+1 for searching notes (comments) scope
merge_request
:
57460
author
:
type
:
performance
ee/spec/requests/search_controller_spec.rb
View file @
8d66eae1
...
...
@@ -70,6 +70,16 @@ RSpec.describe SearchController, type: :request do
it_behaves_like
'an efficient database result'
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment