Commit 3011d182 authored by Kamil Trzciński's avatar Kamil Trzciński

Make `Ci::Group` to be efficient

parent 08f22901
......@@ -9,6 +9,7 @@ module Ci
#
class Group
include StaticModel
include Gitlab::Utils::StrongMemoize
attr_reader :stage, :name, :jobs
......@@ -21,7 +22,11 @@ module Ci
end
def status
@status ||= commit_statuses.status
strong_memoize(:status) do
Gitlab::Ci::Status::GroupedStatuses
.new(@jobs)
.one[:status]
end
end
def detailed_status(current_user)
......
......@@ -21,7 +21,7 @@ module HasStatus
def status
Gitlab::Ci::Status::GroupedStatuses
.new(all)
.one&.dig(:status)
.one[:status]
end
def started_at
......
......@@ -2,6 +2,8 @@
module Ci
class ProcessPipelineService < BaseService
include Gitlab::Utils::StrongMemoize
attr_reader :pipeline
def execute(pipeline, trigger_build_ids = nil)
......
......@@ -12,8 +12,11 @@ module Gitlab
def one(**query)
validate_keys!(query.keys)
item_hash = find_one(data_hash, query)
status_for_key(query, item_hash) if item_hash
if item_hash = find_one(data_hash, query)
status_for_key(query, item_hash)
else
{}
end
end
def group(*keys)
......@@ -42,7 +45,7 @@ module Gitlab
# we request allow_failure when
# we don't have column_names, or such column does exist
columns << :allow_failure if !subject.respond_to?(:column_names) || subject.column_names.include?('allow_failure')
subject
.pluck(*columns)
.map { |attrs| columns.zip(attrs).to_h }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment