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
998aa2a5
Commit
998aa2a5
authored
May 06, 2021
by
Adam Cohen
Committed by
David Kim
May 06, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove N+1 query from Issue::Metrics#record!
parent
d78df37c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
1 deletion
+25
-1
app/models/issue/metrics.rb
app/models/issue/metrics.rb
+5
-1
changelogs/unreleased/4794-add-eager-loading-to-issue-metrics.yml
...gs/unreleased/4794-add-eager-loading-to-issue-metrics.yml
+5
-0
spec/models/issue/metrics_spec.rb
spec/models/issue/metrics_spec.rb
+15
-0
No files found.
app/models/issue/metrics.rb
View file @
998aa2a5
...
...
@@ -24,6 +24,10 @@ class Issue::Metrics < ApplicationRecord
private
def
issue_assigned_to_list_label?
issue
.
labels
.
any?
{
|
label
|
label
.
lists
.
present?
}
# Avoid another DB lookup when issue.labels are empty by adding a guard clause here
# We can't use issue.labels.empty? because that will cause a `Label Exists?` DB lookup
return
false
if
issue
.
labels
.
length
==
0
# rubocop:disable Style/ZeroLengthPredicate
issue
.
labels
.
includes
(
:lists
).
any?
{
|
label
|
label
.
lists
.
present?
}
end
end
changelogs/unreleased/4794-add-eager-loading-to-issue-metrics.yml
0 → 100644
View file @
998aa2a5
---
title
:
Remove N+1 query from Issue::Metrics#record
merge_request
:
60589
author
:
type
:
performance
spec/models/issue/metrics_spec.rb
View file @
998aa2a5
...
...
@@ -80,5 +80,20 @@ RSpec.describe Issue::Metrics do
expect
(
metrics
.
first_added_to_board_at
).
to
be_like_time
(
time
)
end
end
describe
"#record!"
do
it
"does not cause an N+1 query"
do
label
=
create
(
:label
)
subject
.
update!
(
label_ids:
[
label
.
id
])
control_count
=
ActiveRecord
::
QueryRecorder
.
new
{
Issue
::
Metrics
.
find_by
(
issue:
subject
).
record!
}.
count
additional_labels
=
create_list
(
:label
,
4
)
subject
.
update!
(
label_ids:
additional_labels
.
map
(
&
:id
))
expect
{
Issue
::
Metrics
.
find_by
(
issue:
subject
).
record!
}.
not_to
exceed_query_limit
(
control_count
)
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