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
5d488073
Commit
5d488073
authored
Mar 30, 2021
by
Dmitry Gruzd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix N+1 queries for milestone search
parent
aed677b9
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
21 additions
and
4 deletions
+21
-4
app/models/milestone.rb
app/models/milestone.rb
+4
-0
app/presenters/search_service_presenter.rb
app/presenters/search_service_presenter.rb
+2
-1
changelogs/unreleased/227383-fix-search-n-plus-1.yml
changelogs/unreleased/227383-fix-search-n-plus-1.yml
+5
-0
ee/app/models/ee/milestone.rb
ee/app/models/ee/milestone.rb
+9
-0
ee/spec/features/search/elastic/global_search_spec.rb
ee/spec/features/search/elastic/global_search_spec.rb
+1
-3
No files found.
app/models/milestone.rb
View file @
5d488073
...
...
@@ -89,6 +89,10 @@ class Milestone < ApplicationRecord
.
order
(
:project_id
,
:group_id
,
:due_date
).
select
(
'DISTINCT ON (project_id, group_id) id'
)
end
def
self
.
with_web_entity_associations
preload
(
:group
,
project:
[
:project_feature
,
group:
[
:parent
],
namespace: :route
])
end
def
participants
User
.
joins
(
assigned_issues: :milestone
).
where
(
"milestones.id = ?"
,
id
).
distinct
end
...
...
app/presenters/search_service_presenter.rb
View file @
5d488073
...
...
@@ -10,7 +10,8 @@ class SearchServicePresenter < Gitlab::View::Presenter::Delegated
issues: :with_web_entity_associations
,
merge_requests: :with_web_entity_associations
,
epics: :with_web_entity_associations
,
notes: :with_web_entity_associations
notes: :with_web_entity_associations
,
milestones: :with_web_entity_associations
}.
freeze
SORT_ENABLED_SCOPES
=
%w(issues merge_requests)
.
freeze
...
...
changelogs/unreleased/227383-fix-search-n-plus-1.yml
0 → 100644
View file @
5d488073
---
title
:
Fix N+1 for searching milestone scope
merge_request
:
57715
author
:
type
:
performance
ee/app/models/ee/milestone.rb
View file @
5d488073
...
...
@@ -10,6 +10,15 @@ module EE
has_many
:boards
end
class_methods
do
extend
::
Gitlab
::
Utils
::
Override
override
:with_web_entity_associations
def
with_web_entity_associations
super
.
preload
(
project:
[
group:
[
:saml_provider
]])
end
end
def
supports_milestone_charts?
resource_parent
&
.
feature_available?
(
:milestone_charts
)
&&
weight_available?
end
...
...
ee/spec/features/search/elastic/global_search_spec.rb
View file @
5d488073
...
...
@@ -78,9 +78,7 @@ RSpec.describe 'Global elastic search', :elastic, :sidekiq_inline do
let
(
:object
)
{
:milestone
}
let
(
:creation_args
)
{
{
project:
project
}
}
let
(
:path
)
{
search_path
(
search:
'*'
,
scope:
'milestones'
)
}
# N+1 queries still exist and will be fixed per
# https://gitlab.com/gitlab-org/gitlab/-/issues/325887
let
(
:query_count_multiplier
)
{
1
}
let
(
:query_count_multiplier
)
{
0
}
it_behaves_like
'an efficient database result'
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