Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
21fdc1ed
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
21fdc1ed
编写于
8月 10, 2016
作者:
L
Lin Jen-Shin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Cleanup the use of duration and optimize some queries
上级
831b6c8f
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
39 addition
and
50 deletion
+39
-50
app/helpers/time_helper.rb
app/helpers/time_helper.rb
+3
-19
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+5
-5
app/models/commit_status.rb
app/models/commit_status.rb
+7
-7
app/models/concerns/statuseable.rb
app/models/concerns/statuseable.rb
+10
-5
app/views/admin/builds/_build.html.haml
app/views/admin/builds/_build.html.haml
+1
-1
app/views/projects/ci/builds/_build.html.haml
app/views/projects/ci/builds/_build.html.haml
+1
-1
app/views/projects/ci/pipelines/_pipeline.html.haml
app/views/projects/ci/pipelines/_pipeline.html.haml
+2
-2
app/views/projects/pipelines/_info.html.haml
app/views/projects/pipelines/_info.html.haml
+2
-2
spec/helpers/time_helper_spec.rb
spec/helpers/time_helper_spec.rb
+8
-8
未找到文件。
app/helpers/time_helper.rb
浏览文件 @
21fdc1ed
...
@@ -15,25 +15,9 @@ module TimeHelper
...
@@ -15,25 +15,9 @@ module TimeHelper
"
#{
from
.
to_s
(
:short
)
}
-
#{
to
.
to_s
(
:short
)
}
"
"
#{
from
.
to_s
(
:short
)
}
-
#{
to
.
to_s
(
:short
)
}
"
end
end
def
duration_in_numbers
(
finished_at
,
started_at
)
def
duration_in_numbers
(
duration
)
interval
=
interval_in_seconds
(
started_at
,
finished_at
)
time_format
=
duration
<
1
.
hour
?
"%M:%S"
:
"%H:%M:%S"
duration_in_numbers_from_interval
(
interval
)
Time
.
at
(
duration
).
utc
.
strftime
(
time_format
)
end
def
duration_in_numbers_from_interval
(
interval
)
time_format
=
interval
<
1
.
hour
?
"%M:%S"
:
"%H:%M:%S"
Time
.
at
(
interval
).
utc
.
strftime
(
time_format
)
end
private
def
interval_in_seconds
(
started_at
,
finished_at
=
nil
)
if
started_at
&&
finished_at
finished_at
.
to_i
-
started_at
.
to_i
elsif
started_at
Time
.
now
.
to_i
-
started_at
.
to_i
end
end
end
end
end
app/models/ci/pipeline.rb
浏览文件 @
21fdc1ed
...
@@ -34,6 +34,10 @@ module Ci
...
@@ -34,6 +34,10 @@ module Ci
CommitStatus
.
where
(
pipeline:
pluck
(
:id
)).
stages
CommitStatus
.
where
(
pipeline:
pluck
(
:id
)).
stages
end
end
def
self
.
duration
where
.
not
(
duration:
nil
).
pluck
(
:duration
).
inject
(
0
,
&
:
+
)
end
def
project_id
def
project_id
project
.
id
project
.
id
end
end
...
@@ -213,10 +217,6 @@ module Ci
...
@@ -213,10 +217,6 @@ module Ci
]
]
end
end
def
wall_clock_duration
finished_at
.
to_i
-
started_at
.
to_i
if
finished_at
&&
started_at
end
private
private
def
build_builds_for_stages
(
stages
,
user
,
status
,
trigger_request
)
def
build_builds_for_stages
(
stages
,
user
,
status
,
trigger_request
)
...
@@ -240,7 +240,7 @@ module Ci
...
@@ -240,7 +240,7 @@ module Ci
end
end
self
.
started_at
=
statuses
.
started_at
self
.
started_at
=
statuses
.
started_at
self
.
finished_at
=
statuses
.
finished_at
self
.
finished_at
=
statuses
.
finished_at
self
.
duration
=
statuses
.
latest
.
duration
self
.
duration
=
calculate_duration
.
to_i
save
save
end
end
...
...
app/models/commit_status.rb
浏览文件 @
21fdc1ed
...
@@ -21,6 +21,7 @@ class CommitStatus < ActiveRecord::Base
...
@@ -21,6 +21,7 @@ class CommitStatus < ActiveRecord::Base
where
(
id:
max_id
.
group
(
:name
,
:commit_id
))
where
(
id:
max_id
.
group
(
:name
,
:commit_id
))
end
end
scope
:retried
,
->
{
where
.
not
(
id:
latest
)
}
scope
:retried
,
->
{
where
.
not
(
id:
latest
)
}
scope
:ordered
,
->
{
order
(
:name
)
}
scope
:ordered
,
->
{
order
(
:name
)
}
scope
:ignored
,
->
{
where
(
allow_failure:
true
,
status:
[
:failed
,
:canceled
])
}
scope
:ignored
,
->
{
where
(
allow_failure:
true
,
status:
[
:failed
,
:canceled
])
}
...
@@ -83,18 +84,17 @@ class CommitStatus < ActiveRecord::Base
...
@@ -83,18 +84,17 @@ class CommitStatus < ActiveRecord::Base
end
end
end
end
def
self
.
duration
select
(
:started_at
,
:finished_at
).
all
.
map
(
&
:duration
).
compact
.
inject
(
0
,
&
:
+
)
end
def
ignored?
def
ignored?
allow_failure?
&&
(
failed?
||
canceled?
)
allow_failure?
&&
(
failed?
||
canceled?
)
end
end
def
duration
def
duration
duration
=
calculate_duration
if
started_at
&&
finished_at
finished_at
-
started_at
elsif
started_at
Time
.
now
-
started_at
end
duration
end
end
def
stuck?
def
stuck?
...
...
app/models/concerns/statuseable.rb
浏览文件 @
21fdc1ed
...
@@ -31,11 +31,6 @@ module Statuseable
...
@@ -31,11 +31,6 @@ module Statuseable
all
.
pluck
(
self
.
status_sql
).
first
all
.
pluck
(
self
.
status_sql
).
first
end
end
def
duration
duration_array
=
all
.
map
(
&
:duration
).
compact
duration_array
.
reduce
(:
+
)
end
def
started_at
def
started_at
all
.
minimum
(
:started_at
)
all
.
minimum
(
:started_at
)
end
end
...
@@ -78,4 +73,14 @@ module Statuseable
...
@@ -78,4 +73,14 @@ module Statuseable
def
complete?
def
complete?
canceled?
||
success?
||
failed?
canceled?
||
success?
||
failed?
end
end
private
def
calculate_duration
if
started_at
&&
finished_at
finished_at
-
started_at
elsif
started_at
Time
.
now
-
started_at
end
end
end
end
app/views/admin/builds/_build.html.haml
浏览文件 @
21fdc1ed
...
@@ -51,7 +51,7 @@
...
@@ -51,7 +51,7 @@
-
if
build
.
duration
-
if
build
.
duration
%p
.duration
%p
.duration
=
custom_icon
(
"icon_timer"
)
=
custom_icon
(
"icon_timer"
)
=
duration_in_numbers
(
build
.
finished_at
,
build
.
started_at
)
=
duration_in_numbers
(
build
.
duration
)
-
if
build
.
finished_at
-
if
build
.
finished_at
%p
.finished-at
%p
.finished-at
...
...
app/views/projects/ci/builds/_build.html.haml
浏览文件 @
21fdc1ed
...
@@ -63,7 +63,7 @@
...
@@ -63,7 +63,7 @@
-
if
build
.
duration
-
if
build
.
duration
%p
.duration
%p
.duration
=
custom_icon
(
"icon_timer"
)
=
custom_icon
(
"icon_timer"
)
=
duration_in_numbers
(
build
.
finished_at
,
build
.
started_at
)
=
duration_in_numbers
(
build
.
duration
)
-
if
build
.
finished_at
-
if
build
.
finished_at
%p
.finished-at
%p
.finished-at
=
icon
(
"calendar"
)
=
icon
(
"calendar"
)
...
...
app/views/projects/ci/pipelines/_pipeline.html.haml
浏览文件 @
21fdc1ed
...
@@ -46,10 +46,10 @@
...
@@ -46,10 +46,10 @@
\-
\-
%td
%td
-
if
pipeline
.
wall_clock_
duration
-
if
pipeline
.
duration
%p
.duration
%p
.duration
=
custom_icon
(
"icon_timer"
)
=
custom_icon
(
"icon_timer"
)
=
duration_in_numbers
_from_interval
(
pipeline
.
wall_clock_
duration
)
=
duration_in_numbers
(
pipeline
.
duration
)
-
if
pipeline
.
finished_at
-
if
pipeline
.
finished_at
%p
.finished-at
%p
.finished-at
=
icon
(
"calendar"
)
=
icon
(
"calendar"
)
...
...
app/views/projects/pipelines/_info.html.haml
浏览文件 @
21fdc1ed
...
@@ -7,9 +7,9 @@
...
@@ -7,9 +7,9 @@
-
if
@pipeline
.
ref
-
if
@pipeline
.
ref
for
for
=
link_to
@pipeline
.
ref
,
namespace_project_commits_path
(
@project
.
namespace
,
@project
,
@pipeline
.
ref
),
class:
"monospace"
=
link_to
@pipeline
.
ref
,
namespace_project_commits_path
(
@project
.
namespace
,
@project
,
@pipeline
.
ref
),
class:
"monospace"
-
if
@pipeline
.
wall_clock_
duration
-
if
@pipeline
.
duration
in
in
=
time_interval_in_words
(
@pipeline
.
wall_clock_
duration
)
=
time_interval_in_words
(
@pipeline
.
duration
)
.pull-right
.pull-right
=
link_to
namespace_project_pipeline_path
(
@project
.
namespace
,
@project
,
@pipeline
),
class:
"ci-status ci-
#{
@pipeline
.
status
}
"
do
=
link_to
namespace_project_pipeline_path
(
@project
.
namespace
,
@project
,
@pipeline
),
class:
"ci-status ci-
#{
@pipeline
.
status
}
"
do
...
...
spec/helpers/time_helper_spec.rb
浏览文件 @
21fdc1ed
...
@@ -19,16 +19,16 @@ describe TimeHelper do
...
@@ -19,16 +19,16 @@ describe TimeHelper do
describe
"#duration_in_numbers"
do
describe
"#duration_in_numbers"
do
it
"returns minutes and seconds"
do
it
"returns minutes and seconds"
do
duration
_in_number
s
=
{
duration
s_and_expectation
s
=
{
[
100
,
0
]
=>
"01:40"
,
100
=>
"01:40"
,
[
121
,
0
]
=>
"02:01"
,
121
=>
"02:01"
,
[
3721
,
0
]
=>
"01:02:01"
,
3721
=>
"01:02:01"
,
[
0
,
0
]
=>
"00:00"
,
0
=>
"00:00"
,
[
nil
,
Time
.
now
.
to_i
-
42
]
=>
"00:42"
42
=>
"00:42"
}
}
duration
_in_numbers
.
each
do
|
interval
,
expectation
|
duration
s_and_expectations
.
each
do
|
duration
,
expectation
|
expect
(
duration_in_numbers
(
*
interval
)).
to
eq
(
expectation
)
expect
(
duration_in_numbers
(
duration
)).
to
eq
(
expectation
)
end
end
end
end
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录