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
789c4376
Commit
789c4376
authored
Apr 06, 2021
by
Furkan Ayhan
Committed by
Dmytro Zaporozhets (DZ)
Apr 06, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Preload associations in Ci::Pipeline#cancel_running
parent
3d849927
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
4 deletions
+48
-4
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+12
-4
changelogs/unreleased/21098-reducing-cancel-sql-queries.yml
changelogs/unreleased/21098-reducing-cancel-sql-queries.yml
+5
-0
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+31
-0
No files found.
app/models/ci/pipeline.rb
View file @
789c4376
...
...
@@ -584,10 +584,18 @@ module Ci
end
def
cancel_running
(
retries:
nil
)
retry_optimistic_lock
(
cancelable_statuses
,
retries
,
name:
'ci_pipeline_cancel_running'
)
do
|
cancelable
|
cancelable
.
find_each
do
|
job
|
yield
(
job
)
if
block_given?
job
.
cancel
commit_status_relations
=
[
:project
,
:pipeline
]
ci_build_relations
=
[
:deployment
,
:taggings
]
retry_optimistic_lock
(
cancelable_statuses
,
retries
,
name:
'ci_pipeline_cancel_running'
)
do
|
cancelables
|
cancelables
.
find_in_batches
do
|
batch
|
ActiveRecord
::
Associations
::
Preloader
.
new
.
preload
(
batch
,
commit_status_relations
)
ActiveRecord
::
Associations
::
Preloader
.
new
.
preload
(
batch
.
select
{
|
job
|
job
.
is_a?
(
Ci
::
Build
)
},
ci_build_relations
)
batch
.
each
do
|
job
|
yield
(
job
)
if
block_given?
job
.
cancel
end
end
end
end
...
...
changelogs/unreleased/21098-reducing-cancel-sql-queries.yml
0 → 100644
View file @
789c4376
---
title
:
Preload associations in Ci::Pipeline#cancel_running
merge_request
:
58484
author
:
type
:
performance
spec/models/ci/pipeline_spec.rb
View file @
789c4376
...
...
@@ -2635,6 +2635,37 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
expect
(
latest_status
).
to
eq
%w(canceled canceled)
end
end
context
'preloading relations'
do
let
(
:pipeline1
)
{
create
(
:ci_empty_pipeline
,
:created
)
}
let
(
:pipeline2
)
{
create
(
:ci_empty_pipeline
,
:created
)
}
before
do
create
(
:ci_build
,
:pending
,
pipeline:
pipeline1
)
create
(
:generic_commit_status
,
:pending
,
pipeline:
pipeline1
)
create
(
:ci_build
,
:pending
,
pipeline:
pipeline2
)
create
(
:ci_build
,
:pending
,
pipeline:
pipeline2
)
create
(
:generic_commit_status
,
:pending
,
pipeline:
pipeline2
)
create
(
:generic_commit_status
,
:pending
,
pipeline:
pipeline2
)
create
(
:generic_commit_status
,
:pending
,
pipeline:
pipeline2
)
end
it
'preloads relations for each build to avoid N+1 queries'
do
control1
=
ActiveRecord
::
QueryRecorder
.
new
do
pipeline1
.
cancel_running
end
control2
=
ActiveRecord
::
QueryRecorder
.
new
do
pipeline2
.
cancel_running
end
extra_update_queries
=
3
# transition ... => :canceled
extra_generic_commit_status_validation_queries
=
2
# name_uniqueness_across_types
expect
(
control2
.
count
).
to
eq
(
control1
.
count
+
extra_update_queries
+
extra_generic_commit_status_validation_queries
)
end
end
end
describe
'#retry_failed'
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