BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
85c88f45
Commit
85c88f45
authored
Sep 15, 2017
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'projects-controller-show' into 'master'
SQL performance improvements for ProjectsController#show See merge request gitlab-org/gitlab-ce!14226
parents
2e7fe6ea
72190099
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
121 additions
and
16 deletions
+121
-16
pipeline.rb
app/models/ci/pipeline.rb
+4
-0
project.rb
app/models/project.rb
+17
-0
_download.html.haml
app/views/projects/buttons/_download.html.haml
+14
-16
memoize-the-latest-builds-of-a-pipeline.yml
...gs/unreleased/memoize-the-latest-builds-of-a-pipeline.yml
+5
-0
projects-controller-show.yml
changelogs/unreleased/projects-controller-show.yml
+5
-0
pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+20
-0
project_spec.rb
spec/models/project_spec.rb
+56
-0
No files found.
app/models/ci/pipeline.rb
View file @
85c88f45
...
...
@@ -453,6 +453,10 @@ module Ci
.
fabricate!
end
def
latest_builds_with_artifacts
@latest_builds_with_artifacts
||=
builds
.
latest
.
with_artifacts
end
private
def
ci_yaml_from_repo
...
...
app/models/project.rb
View file @
85c88f45
...
...
@@ -1163,6 +1163,23 @@ class Project < ActiveRecord::Base
pipelines
.
order
(
id: :desc
).
find_by
(
sha:
sha
,
ref:
ref
)
end
def
latest_successful_pipeline_for_default_branch
if
defined?
(
@latest_successful_pipeline_for_default_branch
)
return
@latest_successful_pipeline_for_default_branch
end
@latest_successful_pipeline_for_default_branch
=
pipelines
.
latest_successful_for
(
default_branch
)
end
def
latest_successful_pipeline_for
(
ref
=
nil
)
if
ref
&&
ref
!=
default_branch
pipelines
.
latest_successful_for
(
ref
)
else
latest_successful_pipeline_for_default_branch
end
end
def
enable_ci
project_feature
.
update_attribute
(
:builds_access_level
,
ProjectFeature
::
ENABLED
)
end
...
...
app/views/projects/buttons/_download.html.haml
View file @
85c88f45
-
pipeline
=
local_assigns
.
fetch
(
:pipeline
)
{
project
.
pipelines
.
latest_successful
_for
(
ref
)
}
-
pipeline
=
local_assigns
.
fetch
(
:pipeline
)
{
project
.
latest_successful_pipeline
_for
(
ref
)
}
-
if
!
project
.
empty_repo?
&&
can?
(
current_user
,
:download_code
,
project
)
.project-action-button.dropdown.inline
>
...
...
@@ -26,18 +26,16 @@
%i
.fa.fa-download
%span
=
_
(
'Download tar'
)
-
if
pipeline
-
artifacts
=
pipeline
.
builds
.
latest
.
with_artifacts
-
if
artifacts
.
any?
%li
.dropdown-header
Artifacts
-
unless
pipeline
.
latest?
-
latest_pipeline
=
project
.
pipeline_for
(
ref
)
%li
.unclickable
=
ci_status_for_statuseable
(
latest_pipeline
)
%li
.dropdown-header
Previous Artifacts
-
artifacts
.
each
do
|
job
|
%li
=
link_to
latest_succeeded_project_artifacts_path
(
project
,
"
#{
ref
}
/download"
,
job:
job
.
name
),
rel:
'nofollow'
,
download:
''
do
%i
.fa.fa-download
%span
#{
s_
(
'DownloadArtifacts|Download'
)
}
'
#{
job
.
name
}
'
-
if
pipeline
&&
pipeline
.
latest_builds_with_artifacts
.
any?
%li
.dropdown-header
Artifacts
-
unless
pipeline
.
latest?
-
latest_pipeline
=
project
.
pipeline_for
(
ref
)
%li
.unclickable
=
ci_status_for_statuseable
(
latest_pipeline
)
%li
.dropdown-header
Previous Artifacts
-
pipeline
.
latest_builds_with_artifacts
.
each
do
|
job
|
%li
=
link_to
latest_succeeded_project_artifacts_path
(
project
,
"
#{
ref
}
/download"
,
job:
job
.
name
),
rel:
'nofollow'
,
download:
''
do
%i
.fa.fa-download
%span
#{
s_
(
'DownloadArtifacts|Download'
)
}
'
#{
job
.
name
}
'
changelogs/unreleased/memoize-the-latest-builds-of-a-pipeline.yml
0 → 100644
View file @
85c88f45
---
title
:
"
Memoize
the
latest
builds
of
a
pipeline
on
a
project's
homepage"
merge_request
:
author
:
type
:
other
changelogs/unreleased/projects-controller-show.yml
0 → 100644
View file @
85c88f45
---
title
:
Memoize pipelines for project download buttons
merge_request
:
author
:
type
:
other
spec/models/ci/pipeline_spec.rb
View file @
85c88f45
...
...
@@ -1439,4 +1439,24 @@ describe Ci::Pipeline, :mailer do
it_behaves_like
'not sending any notification'
end
end
describe
'#latest_builds_with_artifacts'
do
let!
(
:pipeline
)
{
create
(
:ci_pipeline
,
:success
)
}
let!
(
:build
)
do
create
(
:ci_build
,
:success
,
:artifacts
,
pipeline:
pipeline
)
end
it
'returns the latest builds'
do
expect
(
pipeline
.
latest_builds_with_artifacts
).
to
eq
([
build
])
end
it
'memoizes the returned relation'
do
query_count
=
ActiveRecord
::
QueryRecorder
.
new
{
2
.
times
{
pipeline
.
latest_builds_with_artifacts
.
to_a
}
}
.
count
expect
(
query_count
).
to
eq
(
1
)
end
end
end
spec/models/project_spec.rb
View file @
85c88f45
...
...
@@ -2682,4 +2682,60 @@ describe Project do
end
end
end
describe
'#latest_successful_builds_for'
do
let
(
:project
)
{
build
(
:project
)
}
before
do
allow
(
project
).
to
receive
(
:default_branch
).
and_return
(
'master'
)
end
context
'without a ref'
do
it
'returns a pipeline for the default branch'
do
expect
(
project
)
.
to
receive
(
:latest_successful_pipeline_for_default_branch
)
project
.
latest_successful_pipeline_for
end
end
context
'with the ref set to the default branch'
do
it
'returns a pipeline for the default branch'
do
expect
(
project
)
.
to
receive
(
:latest_successful_pipeline_for_default_branch
)
project
.
latest_successful_pipeline_for
(
project
.
default_branch
)
end
end
context
'with a ref that is not the default branch'
do
it
'returns the latest successful pipeline for the given ref'
do
expect
(
project
.
pipelines
).
to
receive
(
:latest_successful_for
).
with
(
'foo'
)
project
.
latest_successful_pipeline_for
(
'foo'
)
end
end
end
describe
'#latest_successful_pipeline_for_default_branch'
do
let
(
:project
)
{
build
(
:project
)
}
before
do
allow
(
project
).
to
receive
(
:default_branch
).
and_return
(
'master'
)
end
it
'memoizes and returns the latest successful pipeline for the default branch'
do
pipeline
=
double
(
:pipeline
)
expect
(
project
.
pipelines
).
to
receive
(
:latest_successful_for
)
.
with
(
project
.
default_branch
)
.
and_return
(
pipeline
)
.
once
2
.
times
do
expect
(
project
.
latest_successful_pipeline_for_default_branch
)
.
to
eq
(
pipeline
)
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