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
4e95bcd8
Commit
4e95bcd8
authored
Aug 19, 2021
by
Vitali Tatarintev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid cross-joins in PipelinesForMergeRequestFinder
Changelog: added
parent
e92fdefd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
30 deletions
+10
-30
app/finders/ci/pipelines_for_merge_request_finder.rb
app/finders/ci/pipelines_for_merge_request_finder.rb
+6
-30
spec/finders/ci/pipelines_for_merge_request_finder_spec.rb
spec/finders/ci/pipelines_for_merge_request_finder_spec.rb
+4
-0
No files found.
app/finders/ci/pipelines_for_merge_request_finder.rb
View file @
4e95bcd8
...
...
@@ -35,7 +35,7 @@ module Ci
pipelines
=
if
merge_request
.
persisted?
pipelines_using_cte
all_pipelines_for_merge_request
else
triggered_for_branch
.
for_sha
(
commit_shas
)
end
...
...
@@ -47,36 +47,12 @@ module Ci
private
# rubocop: disable CodeReuse/ActiveRecord
def
pipelines_using_cte
sha_relation
=
merge_request
.
all_commits
.
select
(
:sha
).
distinct
def
all_pipelines_for_merge_request
shas
=
merge_request
.
all_commit_shas
pipelines_for_merge_request
=
triggered_by_merge_request
pipelines_for_branch
=
triggered_for_branch
.
for_sha
(
shas
)
cte
=
Gitlab
::
SQL
::
CTE
.
new
(
:shas
,
sha_relation
)
pipelines_for_merge_requests
=
triggered_by_merge_request
pipelines_for_branch
=
filter_by_sha
(
triggered_for_branch
,
cte
)
Ci
::
Pipeline
.
with
(
cte
.
to_arel
)
# rubocop: disable CodeReuse/ActiveRecord
.
from_union
([
pipelines_for_merge_requests
,
pipelines_for_branch
])
end
# rubocop: enable CodeReuse/ActiveRecord
def
filter_by_sha
(
pipelines
,
cte
)
hex
=
Arel
::
Nodes
::
SqlLiteral
.
new
(
"'hex'"
)
string_sha
=
Arel
::
Nodes
::
NamedFunction
.
new
(
'encode'
,
[
cte
.
table
[
:sha
],
hex
])
join_condition
=
string_sha
.
eq
(
Ci
::
Pipeline
.
arel_table
[
:sha
])
filter_by
(
pipelines
,
cte
,
join_condition
)
end
def
filter_by
(
pipelines
,
cte
,
join_condition
)
shas_table
=
Ci
::
Pipeline
.
arel_table
.
join
(
cte
.
table
,
Arel
::
Nodes
::
InnerJoin
)
.
on
(
join_condition
)
.
join_sources
pipelines
.
joins
(
shas_table
)
# rubocop: disable CodeReuse/ActiveRecord
Ci
::
Pipeline
.
from_union
([
pipelines_for_merge_request
,
pipelines_for_branch
])
end
# NOTE: this method returns only parent merge request pipelines.
...
...
spec/finders/ci/pipelines_for_merge_request_finder_spec.rb
View file @
4e95bcd8
...
...
@@ -196,6 +196,10 @@ RSpec.describe Ci::PipelinesForMergeRequestFinder do
ref:
source_ref
,
sha:
shas
.
first
)
end
let!
(
:branch_pipeline_with_sha_not_belonging_to_merge_request
)
do
create
(
:ci_pipeline
,
source: :push
,
project:
project
,
ref:
source_ref
)
end
let!
(
:detached_merge_request_pipeline_2
)
do
create
(
:ci_pipeline
,
source: :merge_request_event
,
project:
project
,
ref:
source_ref
,
sha:
shas
.
first
,
merge_request:
merge_request_2
)
...
...
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