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
iv
gitlab-ce
Commits
1685b9dc
Commit
1685b9dc
authored
Jun 14, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimise SQL query
parent
ee2e5835
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
13 deletions
+11
-13
app/services/ci/register_build_service.rb
app/services/ci/register_build_service.rb
+11
-13
No files found.
app/services/ci/register_build_service.rb
View file @
1685b9dc
...
...
@@ -7,10 +7,14 @@ module Ci
builds
=
if
current_runner
.
shared?
# this returns builds that are ordered by number of running builds
# we prefer projects that don't use shared runners at all
builds
.
joins
(
"JOIN (
#{
projects_with_builds_for_shared_runners
.
to_sql
}
) AS projects ON ci_builds.gl_project_id=projects.gl_project_id"
).
order
(
'projects.running_builds ASC'
,
'ci_builds.id ASC'
)
builds
.
# don't run projects which have not enables shared runners
joins
(
:project
).
where
(
projects:
{
builds_enabled:
true
,
shared_runners_enabled:
true
})
.
# this returns builds that are ordered by number of running builds
# we prefer projects that don't use shared runners at all
joins
(
"LEFT JOIN (
#{
running_builds_for_shared_runners
.
to_sql
}
) AS project_builds ON ci_builds.gl_project_id=project_builds.gl_project_id"
).
order
(
'COALESCE(project_builds.running_builds, 0) ASC'
,
'ci_builds.id ASC'
)
else
# do run projects which are only assigned to this runner (FIFO)
builds
.
where
(
project:
current_runner
.
projects
.
where
(
builds_enabled:
true
)).
order
(
'created_at ASC'
)
...
...
@@ -38,15 +42,9 @@ module Ci
private
def
projects_with_builds_for_shared_runners
Ci
::
Build
.
running_or_pending
.
joins
(
:project
).
where
(
projects:
{
builds_enabled:
true
,
shared_runners_enabled:
true
}).
group
(
:gl_project_id
).
select
(
:gl_project_id
,
"count(case when status = 'running' AND runner_id = (
#{
shared_runners
.
to_sql
}
) then 1 end) as running_builds"
)
end
def
shared_runners
Ci
::
Runner
.
shared
.
select
(
:id
)
def
running_builds_for_shared_runners
Ci
::
Build
.
running
.
where
(
runner:
Ci
::
Runner
.
shared
).
group
(
:gl_project_id
).
select
(
:gl_project_id
,
'count(*) AS running_builds'
)
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