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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
31b15e3d
Commit
31b15e3d
authored
Sep 23, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify CI projects query
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
0731a7af
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
50 deletions
+31
-50
app/controllers/ci/projects_controller.rb
app/controllers/ci/projects_controller.rb
+6
-3
app/models/ci/project.rb
app/models/ci/project.rb
+1
-0
app/views/ci/projects/_project.html.haml
app/views/ci/projects/_project.html.haml
+24
-26
lib/ci/project_list_builder.rb
lib/ci/project_list_builder.rb
+0
-21
No files found.
app/controllers/ci/projects_controller.rb
View file @
31b15e3d
...
...
@@ -16,12 +16,15 @@ module Ci
end
def
index
@projects
=
Ci
::
Project
.
all
if
current_user
@projects
=
ProjectListBuilder
.
new
.
execute
(
current_user
,
params
[
:search
])
@projects
=
@projects
.
page
(
params
[
:page
]).
per
(
40
)
@total_count
=
@projects
.
size
@projects
=
@projects
.
where
(
gitlab_id:
current_user
.
authorized_projects
.
pluck
(
:id
))
end
@projects
=
@projects
.
includes
(
:last_commit
).
order
(
'ci_commits.created_at DESC'
)
@projects
=
@projects
.
page
(
params
[
:page
]).
per
(
40
)
respond_to
do
|
format
|
format
.
json
do
pager_json
(
"ci/projects/index"
,
@total_count
)
...
...
app/models/ci/project.rb
View file @
31b15e3d
...
...
@@ -41,6 +41,7 @@ module Ci
has_many
:events
,
dependent: :destroy
,
class_name:
'Ci::Event'
has_many
:variables
,
dependent: :destroy
,
class_name:
'Ci::Variable'
has_many
:triggers
,
dependent: :destroy
,
class_name:
'Ci::Trigger'
has_one
:last_commit
,
->
{
order
'ci_commits.created_at DESC'
},
class_name:
'Ci::Commit'
# Project services
has_many
:services
,
dependent: :destroy
,
class_name:
'Ci::Service'
...
...
app/views/ci/projects/_project.html.haml
View file @
31b15e3d
-
if
project
.
gitlab_ci_project
-
ci_project
=
project
.
gitlab_ci_project
-
last_commit
=
ci_project
.
last_commit
%tr
-
last_commit
=
project
.
last_commit
%tr
%td
=
link_to
[
:ci
,
ci_
project
]
do
=
ci_
project
.
name
=
link_to
[
:ci
,
project
]
do
=
project
.
name
%td
-
if
last_commit
=
ci_status_with_icon
(
last_commit
.
status
)
=
commit_link
(
last_commit
)
·
-
if
ci_
project
.
last_commit_date
=
time_ago_in_words
ci_
project
.
last_commit_date
-
if
project
.
last_commit_date
=
time_ago_in_words
project
.
last_commit_date
ago
-
else
No builds yet
%td
-
if
ci_
project
.
public
-
if
project
.
public
%i
.fa.fa-globe
Public
-
else
%i
.fa.fa-lock
Private
%td
=
ci_
project
.
commits
.
count
=
project
.
commits
.
count
lib/ci/project_list_builder.rb
deleted
100644 → 0
View file @
0731a7af
module
Ci
class
ProjectListBuilder
def
execute
(
current_user
,
search
=
nil
)
projects
=
current_user
.
authorized_projects
projects
=
projects
.
search
(
search
)
if
search
projects
.
joins
(
"LEFT JOIN ci_projects ON projects.id = ci_projects.gitlab_id
LEFT JOIN
#{
last_commit_subquery
}
AS last_commit ON
#{
Ci
::
Project
.
table_name
}
.id = last_commit.project_id"
).
reorder
(
"ci_projects.id is NULL ASC,
CASE WHEN last_commit.committed_at IS NULL THEN 1 ELSE 0 END,
last_commit.committed_at DESC"
)
end
private
def
last_commit_subquery
"(SELECT project_id, MAX(committed_at) committed_at FROM
#{
Ci
::
Commit
.
table_name
}
GROUP BY project_id)"
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