diff options
author | Thong Kuah <tkuah@gitlab.com> | 2019-07-01 11:27:58 +0300 |
---|---|---|
committer | Thong Kuah <tkuah@gitlab.com> | 2019-07-08 00:13:21 +0300 |
commit | 1b5b0dea5228ae7fd520c8bca3f03c4799a4d31d (patch) | |
tree | 0969a78c3b959cf33b47a0de308fa385c62af157 /app/models/environment_status.rb | |
parent | 1668f40f430c656ed9c20898605db21a66cb5937 (diff) |
Share project object in EnvironmentStatus
Otherwise, each EnvironmentStatus object instantiates its own project
when really they are the same. Improves query count performance
Diffstat (limited to 'app/models/environment_status.rb')
-rw-r--r-- | app/models/environment_status.rb | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/app/models/environment_status.rb b/app/models/environment_status.rb index 2fb6cadc8cd..2c71520cec1 100644 --- a/app/models/environment_status.rb +++ b/app/models/environment_status.rb @@ -3,11 +3,10 @@ class EnvironmentStatus include Gitlab::Utils::StrongMemoize - attr_reader :environment, :merge_request, :sha + attr_reader :project, :environment, :merge_request, :sha delegate :id, to: :environment delegate :name, to: :environment - delegate :project, to: :environment delegate :status, to: :deployment, allow_nil: true delegate :deployed_at, to: :deployment, allow_nil: true @@ -21,7 +20,8 @@ class EnvironmentStatus build_environments_status(mr, user, mr.merge_pipeline) end - def initialize(environment, merge_request, sha) + def initialize(project, environment, merge_request, sha) + @project = project @environment = environment @merge_request = merge_request @sha = sha @@ -67,7 +67,7 @@ class EnvironmentStatus pipeline.environments.available.map do |environment| next unless Ability.allowed?(user, :read_environment, environment) - EnvironmentStatus.new(environment, mr, pipeline.sha) + EnvironmentStatus.new(pipeline.project, environment, mr, pipeline.sha) end.compact end private_class_method :build_environments_status |