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
0bae8d6f
Commit
0bae8d6f
authored
Jul 23, 2020
by
Igor Drozdov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Preload number of pipeline warnings for commits
parent
2bcfaf6d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
10 deletions
+29
-10
app/models/commit_collection.rb
app/models/commit_collection.rb
+4
-1
changelogs/unreleased/id-fix-n-1-for-commits.yml
changelogs/unreleased/id-fix-n-1-for-commits.yml
+5
-0
spec/models/commit_collection_spec.rb
spec/models/commit_collection_spec.rb
+20
-9
No files found.
app/models/commit_collection.rb
View file @
0bae8d6f
...
...
@@ -47,7 +47,10 @@ class CommitCollection
pipelines
=
project
.
ci_pipelines
.
latest_pipeline_per_commit
(
map
(
&
:id
),
ref
)
each
do
|
commit
|
commit
.
set_latest_pipeline_for_ref
(
ref
,
pipelines
[
commit
.
id
])
pipeline
=
pipelines
[
commit
.
id
]
pipeline
&
.
number_of_warnings
# preload number of warnings
commit
.
set_latest_pipeline_for_ref
(
ref
,
pipeline
)
end
self
...
...
changelogs/unreleased/id-fix-n-1-for-commits.yml
0 → 100644
View file @
0bae8d6f
---
title
:
Preload number of pipeline warnings for commits
merge_request
:
37669
author
:
type
:
performance
spec/models/commit_collection_spec.rb
View file @
0bae8d6f
...
...
@@ -52,27 +52,38 @@ RSpec.describe CommitCollection do
end
describe
'#with_latest_pipeline'
do
let
(
:another_commit
)
{
project
.
commit
(
"60ecb67744cb56576c30214ff52294f8ce2def98"
)
}
let!
(
:pipeline
)
do
create
(
:ci_empty_pipeline
,
ref:
'master'
,
sha:
commit
.
id
,
status:
'success'
,
project:
project
)
create
(
:ci_empty_pipeline
,
ref:
'master'
,
sha:
commit
.
id
,
status:
'success'
,
project:
project
)
end
let!
(
:another_pipeline
)
do
create
(
:ci_empty_pipeline
,
ref:
'master'
,
sha:
another_commit
.
id
,
status:
'success'
,
project:
project
)
end
let
(
:collection
)
{
described_class
.
new
(
project
,
[
commit
])
}
let
(
:collection
)
{
described_class
.
new
(
project
,
[
commit
,
another_commit
])
}
it
'sets the latest pipeline for every commit so no additional queries are necessary'
do
commits
=
collection
.
with_latest_pipeline
(
'master'
)
recorder
=
ActiveRecord
::
QueryRecorder
.
new
do
expect
(
commits
.
map
{
|
c
|
c
.
latest_pipeline
(
'master'
)
})
.
to
eq
([
pipeline
])
.
to
eq
([
pipeline
,
another_pipeline
])
end
expect
(
recorder
.
count
).
to
be_zero
end
it
'performs a single query to fetch pipeline warnings'
do
recorder
=
ActiveRecord
::
QueryRecorder
.
new
do
collection
.
with_latest_pipeline
(
'master'
).
each
do
|
c
|
c
.
latest_pipeline
(
'master'
).
number_of_warnings
.
itself
end
end
expect
(
recorder
.
count
).
to
eq
(
2
)
# 1 for pipelines, 1 for warnings counts
end
end
describe
'#with_markdown_cache'
do
...
...
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