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
8a1c12aa
Commit
8a1c12aa
authored
Apr 06, 2017
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce endpoint optimisations
parent
3015e768
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
31 additions
and
34 deletions
+31
-34
app/models/ci/build.rb
app/models/ci/build.rb
+2
-8
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+12
-15
app/models/project.rb
app/models/project.rb
+11
-3
app/serializers/pipeline_entity.rb
app/serializers/pipeline_entity.rb
+4
-4
app/services/ci/retry_pipeline_service.rb
app/services/ci/retry_pipeline_service.rb
+1
-3
spec/serializers/pipeline_serializer_spec.rb
spec/serializers/pipeline_serializer_spec.rb
+1
-1
No files found.
app/models/ci/build.rb
View file @
8a1c12aa
...
@@ -103,18 +103,13 @@ module Ci
...
@@ -103,18 +103,13 @@ module Ci
end
end
def
playable?
def
playable?
project
.
builds_enabled?
&&
has_commands?
&&
action?
&&
manual?
action?
&&
manual?
end
end
def
action?
def
action?
self
.
when
==
'manual'
self
.
when
==
'manual'
end
end
def
has_commands?
commands
.
present?
end
def
play
(
current_user
)
def
play
(
current_user
)
# Try to queue a current build
# Try to queue a current build
if
self
.
enqueue
if
self
.
enqueue
...
@@ -131,8 +126,7 @@ module Ci
...
@@ -131,8 +126,7 @@ module Ci
end
end
def
retryable?
def
retryable?
project
.
builds_enabled?
&&
has_commands?
&&
success?
||
failed?
||
canceled?
(
success?
||
failed?
||
canceled?
)
end
end
def
retried?
def
retried?
...
...
app/models/ci/pipeline.rb
View file @
8a1c12aa
...
@@ -12,6 +12,12 @@ module Ci
...
@@ -12,6 +12,12 @@ module Ci
has_many
:builds
,
foreign_key: :commit_id
has_many
:builds
,
foreign_key: :commit_id
has_many
:trigger_requests
,
dependent: :destroy
,
foreign_key: :commit_id
has_many
:trigger_requests
,
dependent: :destroy
,
foreign_key: :commit_id
has_many
:pending_builds
,
->
{
pending
},
foreign_key: :commit_id
,
class_name:
'Ci::Build'
has_many
:retryable_builds
,
->
{
latest
.
failed_or_canceled
},
foreign_key: :commit_id
,
class_name:
'Ci::Build'
has_many
:cancelable_statuses
,
->
{
cancelable
},
foreign_key: :commit_id
,
class_name:
'CommitStatus'
has_many
:manual_actions
,
->
{
latest
.
manual_actions
},
foreign_key: :commit_id
,
class_name:
'Ci::Build'
has_many
:artifacts
,
->
{
latest
.
with_artifacts_not_expired
},
foreign_key: :commit_id
,
class_name:
'Ci::Build'
delegate
:id
,
to: :project
,
prefix:
true
delegate
:id
,
to: :project
,
prefix:
true
validates
:sha
,
presence:
{
unless: :importing?
}
validates
:sha
,
presence:
{
unless: :importing?
}
...
@@ -160,10 +166,6 @@ module Ci
...
@@ -160,10 +166,6 @@ module Ci
end
end
end
end
def
artifacts
builds
.
latest
.
with_artifacts_not_expired
.
includes
(
project:
[
:namespace
])
end
def
valid_commit_sha
def
valid_commit_sha
if
self
.
sha
==
Gitlab
::
Git
::
BLANK_SHA
if
self
.
sha
==
Gitlab
::
Git
::
BLANK_SHA
self
.
errors
.
add
(
:sha
,
" cant be 00000000 (branch removal)"
)
self
.
errors
.
add
(
:sha
,
" cant be 00000000 (branch removal)"
)
...
@@ -200,27 +202,22 @@ module Ci
...
@@ -200,27 +202,22 @@ module Ci
!
tag?
!
tag?
end
end
def
manual_actions
builds
.
latest
.
manual_actions
.
includes
(
project:
[
:namespace
])
end
def
stuck?
def
stuck?
builds
.
pending
.
includes
(
:project
)
.
any?
(
&
:stuck?
)
pending_builds
.
any?
(
&
:stuck?
)
end
end
def
retryable?
def
retryable?
builds
.
latest
.
failed_or_canceled
.
any?
(
&
:retryable?
)
retryable_builds
.
any?
end
end
def
cancelable?
def
cancelable?
statuses
.
cancelable
.
any?
cancelable_statuses
.
any?
end
end
def
cancel_running
def
cancel_running
Gitlab
::
OptimisticLocking
.
retry_lock
(
Gitlab
::
OptimisticLocking
.
retry_lock
(
cancelable_statuses
)
do
|
cancelable
|
statuses
.
cancelable
)
do
|
cancelable
|
cancelable
.
find_each
(
&
:cancel
)
cancelable
.
find_each
(
&
:cancel
)
end
end
end
end
def
retry_failed
(
current_user
)
def
retry_failed
(
current_user
)
...
...
app/models/project.rb
View file @
8a1c12aa
...
@@ -1093,15 +1093,23 @@ class Project < ActiveRecord::Base
...
@@ -1093,15 +1093,23 @@ class Project < ActiveRecord::Base
end
end
def
shared_runners
def
shared_runners
shared_runners_available?
?
Ci
::
Runner
.
shared
:
Ci
::
Runner
.
none
@shared_runners
||=
shared_runners_available?
?
Ci
::
Runner
.
shared
:
Ci
::
Runner
.
none
end
def
active_runners
@active_runners
||=
runners
.
active
end
def
active_shared_runners
@active_shared_runners
||=
shared_runners
.
active
end
end
def
any_runners?
(
&
block
)
def
any_runners?
(
&
block
)
if
runners
.
active
.
any?
(
&
block
)
if
active_runners
.
any?
(
&
block
)
return
true
return
true
end
end
shared_runners
.
active
.
any?
(
&
block
)
active_shared_runners
.
any?
(
&
block
)
end
end
def
valid_runners_token?
(
token
)
def
valid_runners_token?
(
token
)
...
...
app/serializers/pipeline_entity.rb
View file @
8a1c12aa
...
@@ -69,13 +69,13 @@ class PipelineEntity < Grape::Entity
...
@@ -69,13 +69,13 @@ class PipelineEntity < Grape::Entity
alias_method
:pipeline
,
:object
alias_method
:pipeline
,
:object
def
can_retry?
def
can_retry?
pipeline
.
retryable?
&&
can?
(
request
.
user
,
:update_pipeline
,
pipeline
)
&&
can?
(
request
.
user
,
:update_pipeline
,
pipeline
)
pipeline
.
retryable?
end
end
def
can_cancel?
def
can_cancel?
pipeline
.
cancelable?
&&
can?
(
request
.
user
,
:update_pipeline
,
pipeline
)
&&
can?
(
request
.
user
,
:update_pipeline
,
pipeline
)
pipeline
.
cancelable?
end
end
def
detailed_status
def
detailed_status
...
...
app/services/ci/retry_pipeline_service.rb
View file @
8a1c12aa
...
@@ -7,9 +7,7 @@ module Ci
...
@@ -7,9 +7,7 @@ module Ci
raise
Gitlab
::
Access
::
AccessDeniedError
raise
Gitlab
::
Access
::
AccessDeniedError
end
end
pipeline
.
builds
.
latest
.
failed_or_canceled
.
find_each
do
|
build
|
pipeline
.
retryable_builds
.
find_each
do
|
build
|
next
unless
build
.
retryable?
Ci
::
RetryBuildService
.
new
(
project
,
current_user
)
Ci
::
RetryBuildService
.
new
(
project
,
current_user
)
.
reprocess
(
build
)
.
reprocess
(
build
)
end
end
...
...
spec/serializers/pipeline_serializer_spec.rb
View file @
8a1c12aa
...
@@ -105,7 +105,7 @@ describe PipelineSerializer do
...
@@ -105,7 +105,7 @@ describe PipelineSerializer do
it
"verifies number of queries"
do
it
"verifies number of queries"
do
recorded
=
ActiveRecord
::
QueryRecorder
.
new
{
subject
}
recorded
=
ActiveRecord
::
QueryRecorder
.
new
{
subject
}
expect
(
recorded
.
count
).
to
be_within
(
32
0
).
of
(
10
)
expect
(
recorded
.
count
).
to
be_within
(
20
0
).
of
(
10
)
end
end
def
create_pipeline
(
status
)
def
create_pipeline
(
status
)
...
...
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