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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
5771972e
Commit
5771972e
authored
Apr 24, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use database query to calculate average stage position
parent
fc6ec8ad
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
10 deletions
+26
-10
app/models/ci/stage.rb
app/models/ci/stage.rb
+7
-5
spec/models/ci/stage_spec.rb
spec/models/ci/stage_spec.rb
+19
-5
No files found.
app/models/ci/stage.rb
View file @
5771972e
...
...
@@ -24,12 +24,14 @@ module Ci
self
.
status
=
DEFAULT_STATUS
if
self
.
status
.
nil?
end
before_validation
do
next
unless
index
.
nil
?
before_validation
unless: :importing?
do
next
if
index
.
present
?
statuses
.
pluck
(
:stage_idx
).
tap
do
|
indices
|
self
.
index
=
indices
.
max_by
{
|
index
|
indices
.
count
(
index
)
}
end
self
.
index
=
statuses
.
select
(
:stage_idx
)
.
where
(
'stage_idx IS NOT NULL'
)
.
group
(
:stage_idx
)
.
order
(
'COUNT(*) DESC'
)
.
first
&
.
stage_idx
.
to_i
end
state_machine
:status
,
initial: :created
do
...
...
spec/models/ci/stage_spec.rb
View file @
5771972e
...
...
@@ -92,16 +92,30 @@ describe Ci::Stage, :models do
context
'when stage has been imported and does not have index set'
do
before
do
stage
.
update_column
(
:index
,
nil
)
end
context
'when stage has statuses'
do
before
do
create
(
:ci_build
,
:running
,
stage_id:
stage
.
id
,
stage_idx:
10
)
end
it
'recalculates index before updating status'
do
expect
(
stage
.
reload
.
index
).
to
be_nil
create
(
:ci_build
,
:running
,
stage_id:
stage
.
id
,
stage_idx:
10
)
stage
.
update_status
expect
(
stage
.
reload
.
index
).
to
eq
10
end
end
it
'recalculates index before updating status'
do
expect
(
stage
.
reload
.
index
).
to
be_nil
context
'when stage does not have statuses'
do
it
'fallbacks to zero'
do
expect
(
stage
.
reload
.
index
).
to
be_nil
stage
.
update_status
stage
.
update_status
expect
(
stage
.
reload
.
index
).
to
eq
10
expect
(
stage
.
reload
.
index
).
to
eq
0
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