Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
GitLab
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
4
Snippets
Groups
Projects
Show more breadcrumbs
GitLab.org
GitLab
Commits
a1224cc4
Verified
Commit
a1224cc4
authored
2 years ago
by
Pedro Pombeiro
Browse files
Options
Downloads
Patches
Plain Diff
Apply suggestion
parent
c24ec26a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/serializers/group_child_entity.rb
+29
-10
29 additions, 10 deletions
app/serializers/group_child_entity.rb
with
29 additions
and
10 deletions
app/serializers/group_child_entity.rb
+
29
−
10
View file @
a1224cc4
...
...
@@ -114,16 +114,35 @@ def can_edit?
end
def
last_pipeline
return
unless
object
.
builds_enabled?
&&
pipeline
=
object
.
pipeline_status
return
unless
pipeline
.
status
.
present?
{
details_path:
project_pipeline_path
(
object
,
pipeline
),
group:
pipeline
.
status
,
icon:
"status_
#{
pipeline
.
status
}
"
,
label:
pipeline
.
status
,
text:
pipeline
.
status
}
return
unless
project?
&&
can?
(
request
.
current_user
,
:read_build
,
object
)
BatchLoader
.
for
(
object
).
batch
do
|
projects
,
loader
|
# rubocop: disable CodeReuse/ActiveRecord
# This will load the project_feature association for all the projects for the line after next line
ActiveRecord
::
Associations
::
Preloader
.
new
.
preload
(
projects
,
:project_feature
)
builds_enabled_projects
=
projects
.
select
(
&
:builds_enabled?
)
# Prefill nil for all the projects
projects
.
each
{
|
project
|
loader
.
call
(
project
,
nil
)
}
# This is to load last_pipeline for all the builds-enabled projects in one SQL
Ci
::
Pipeline
# The DISTINCT select statement will work with the below ORDER statement to return the last pipeline
.
select
(
"DISTINCT ON (project_id) *"
)
.
where
(
project_id:
builds_enabled_projects
.
map
(
&
:id
)).
ci_sources
.
order
(
:project_id
,
id: :desc
)
# `each` is used instead of `find_each` because `find_each` will overwrite the above ORDER statement that we
# need for the last pipelines query to work.
.
each
do
|
pipeline
|
project
=
projects
.
find
{
|
project
|
project
.
id
==
pipeline
.
project_id
}
loader
.
call
(
project
,
{
details_path:
project_pipeline_path
(
project
,
pipeline
),
group:
pipeline
.
status
,
icon:
"status_
#{
pipeline
.
status
}
"
,
label:
pipeline
.
status
,
text:
pipeline
.
status
})
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment