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
6940968e
Commit
6940968e
authored
Jun 04, 2020
by
Terri Chu
Committed by
Peter Leitzen
Jun 04, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix N+1 queries for Elastic Search milestones scope
parent
9149d54a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
1 deletion
+18
-1
app/models/milestone.rb
app/models/milestone.rb
+1
-0
ee/changelogs/unreleased/215710-improve-performance-of-search-api-advanced-milestones-scope.yml
...e-performance-of-search-api-advanced-milestones-scope.yml
+5
-0
ee/spec/requests/api/search_spec.rb
ee/spec/requests/api/search_spec.rb
+10
-0
lib/api/search.rb
lib/api/search.rb
+2
-1
No files found.
app/models/milestone.rb
View file @
6940968e
...
...
@@ -28,6 +28,7 @@ class Milestone < ApplicationRecord
scope
:order_by_name_asc
,
->
{
order
(
Arel
::
Nodes
::
Ascending
.
new
(
arel_table
[
:title
].
lower
))
}
scope
:reorder_by_due_date_asc
,
->
{
reorder
(
Gitlab
::
Database
.
nulls_last_order
(
'due_date'
,
'ASC'
))
}
scope
:with_api_entity_associations
,
->
{
preload
(
project:
[
:project_feature
,
:route
,
namespace: :route
])
}
validates_associated
:milestone_releases
,
message:
->
(
_
,
obj
)
{
obj
[
:value
].
map
(
&
:errors
).
map
(
&
:full_messages
).
join
(
","
)
}
...
...
ee/changelogs/unreleased/215710-improve-performance-of-search-api-advanced-milestones-scope.yml
0 → 100644
View file @
6940968e
---
title
:
Fix N+1 queries for Elastic Search milestones scope.
merge_request
:
33327
author
:
type
:
performance
ee/spec/requests/api/search_spec.rb
View file @
6940968e
...
...
@@ -212,6 +212,16 @@ RSpec.describe API::Search do
end
it_behaves_like
'pagination'
,
scope:
'milestones'
it
'avoids N+1 queries'
do
control
=
ActiveRecord
::
QueryRecorder
.
new
{
get
api
(
endpoint
,
user
),
params:
{
scope:
'milestones'
,
search:
'*'
}
}
create_list
(
:milestone
,
3
,
project:
project
)
create_list
(
:milestone
,
2
,
project:
create
(
:project
,
:public
))
ensure_elasticsearch_index!
expect
{
get
api
(
endpoint
,
user
),
params:
{
scope:
'milestones'
,
search:
'*'
}
}.
not_to
exceed_query_limit
(
control
.
count
)
end
end
context
'for users scope'
,
:sidekiq_inline
do
...
...
lib/api/search.rb
View file @
6940968e
...
...
@@ -23,7 +23,8 @@ module API
SCOPE_PRELOAD_METHOD
=
{
merge_requests: :with_api_entity_associations
,
projects: :with_api_entity_associations
,
issues: :with_api_entity_associations
issues: :with_api_entity_associations
,
milestones: :with_api_entity_associations
}.
freeze
def
search
(
additional_params
=
{})
...
...
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