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
5e6a52ca
Commit
5e6a52ca
authored
Nov 04, 2018
by
Kamil Trzciński
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve performance of `Pipeline.newest_first`
parent
2530bc0c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
17 deletions
+44
-17
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+8
-6
ee/app/models/ee/ci/pipeline.rb
ee/app/models/ee/ci/pipeline.rb
+1
-1
ee/app/models/ee/project.rb
ee/app/models/ee/project.rb
+2
-2
ee/spec/models/project_spec.rb
ee/spec/models/project_spec.rb
+33
-8
No files found.
app/models/ci/pipeline.rb
View file @
5e6a52ca
...
...
@@ -194,22 +194,24 @@ module Ci
#
# ref - The name (or names) of the branch(es)/tag(s) to limit the list of
# pipelines to.
def
self
.
newest_first
(
ref
=
nil
)
# limit - This limits a backlog search, default to 100.
def
self
.
newest_first
(
ref:
nil
,
limit:
100
)
relation
=
order
(
id: :desc
)
ref
?
relation
.
where
(
ref:
ref
)
:
relation
relation
=
relation
.
where
(
ref:
ref
)
if
ref
relation
=
relation
.
where
(
id:
relation
.
limit
(
limit
).
select
(
:id
))
if
limit
relation
end
def
self
.
latest_status
(
ref
=
nil
)
newest_first
(
ref
).
pluck
(
:status
).
first
newest_first
(
ref
:
ref
).
pluck
(
:status
).
first
end
def
self
.
latest_successful_for
(
ref
)
newest_first
(
ref
).
success
.
take
newest_first
(
ref
:
ref
).
success
.
take
end
def
self
.
latest_successful_for_refs
(
refs
)
relation
=
newest_first
(
refs
).
success
relation
=
newest_first
(
ref
:
ref
s
).
success
relation
.
each_with_object
({})
do
|
pipeline
,
hash
|
hash
[
pipeline
.
ref
]
||=
pipeline
...
...
ee/app/models/ee/ci/pipeline.rb
View file @
5e6a52ca
...
...
@@ -22,7 +22,7 @@ module EE
# The new `reports:` syntax reports
scope
:with_security_reports
,
->
do
where
(
'EXISTS (?)'
,
Ci
::
Build
.
select
(
1
).
latest
.
with_security_reports
.
where
(
'ci_pipelines.id=ci_build.commit_id'
))
where
(
'EXISTS (?)'
,
::
Ci
::
Build
.
latest
.
with_security_reports
.
where
(
'ci_pipelines.id=ci_builds.commit_id'
).
select
(
1
))
end
# This structure describes feature levels
...
...
ee/app/models/ee/project.rb
View file @
5e6a52ca
...
...
@@ -110,8 +110,8 @@ module EE
end
def
latest_pipeline_with_security_reports
pipelines
.
newest_first
(
default_branch
).
with_security_reports
.
first
||
pipelines
.
newest_first
(
default_branch
).
with_legacy_security_reports
.
first
pipelines
.
newest_first
(
ref:
default_branch
).
with_security_reports
.
first
||
pipelines
.
newest_first
(
ref:
default_branch
).
with_legacy_security_reports
.
first
end
def
environments_for_scope
(
scope
)
...
...
ee/spec/models/project_spec.rb
View file @
5e6a52ca
...
...
@@ -1498,17 +1498,42 @@ describe Project do
describe
'#latest_pipeline_with_security_reports'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:pipeline_1
)
{
create
(
:ci_pipeline_without_jobs
,
project:
project
)
}
let
(
:pipeline_2
)
{
create
(
:ci_pipeline_without_jobs
,
project:
project
)
}
let
(
:pipeline_3
)
{
create
(
:ci_pipeline_without_jobs
,
project:
project
)
}
let
!
(
:pipeline_1
)
{
create
(
:ci_pipeline_without_jobs
,
project:
project
)
}
let
!
(
:pipeline_2
)
{
create
(
:ci_pipeline_without_jobs
,
project:
project
)
}
let
!
(
:pipeline_3
)
{
create
(
:ci_pipeline_without_jobs
,
project:
project
)
}
before
do
create
(
:ee_ci_build
,
:legacy_sast
,
pipeline:
pipeline_1
)
create
(
:ee_ci_build
,
:legacy_sast
,
pipeline:
pipeline_2
)
subject
{
project
.
latest_pipeline_with_security_reports
}
context
'when legacy reports are used'
do
before
do
create
(
:ee_ci_build
,
:legacy_sast
,
pipeline:
pipeline_1
)
create
(
:ee_ci_build
,
:legacy_sast
,
pipeline:
pipeline_2
)
end
it
"returns the latest pipeline with security reports"
do
is_expected
.
to
eq
(
pipeline_2
)
end
end
it
"returns the latest pipeline with security reports"
do
expect
(
project
.
latest_pipeline_with_legacy_security_reports
).
to
eq
(
pipeline_2
)
context
'when new reports are used'
do
before
do
create
(
:ee_ci_build
,
:sast
,
pipeline:
pipeline_1
)
create
(
:ee_ci_build
,
:sast
,
pipeline:
pipeline_2
)
end
it
"returns the latest pipeline with security reports"
do
is_expected
.
to
eq
(
pipeline_2
)
end
context
'when legacy used'
do
before
do
create
(
:ee_ci_build
,
:legacy_sast
,
pipeline:
pipeline_3
)
end
it
"prefers the new reports"
do
is_expected
.
to
eq
(
pipeline_2
)
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