Commit e49229aa authored by Grzegorz Bizon's avatar Grzegorz Bizon

Refactor methods for environments in project model

parent c95b88e6
...@@ -37,7 +37,7 @@ class Environment < ActiveRecord::Base ...@@ -37,7 +37,7 @@ class Environment < ActiveRecord::Base
state :stopped state :stopped
end end
def recently_updated_on?(ref) def recently_updated_on_branch?(ref)
ref.to_s == last_deployment.ref ref.to_s == last_deployment.ref
end end
......
...@@ -1296,12 +1296,19 @@ class Project < ActiveRecord::Base ...@@ -1296,12 +1296,19 @@ class Project < ActiveRecord::Base
.group(:environment_id) .group(:environment_id)
.select(:environment_id) .select(:environment_id)
envs = environments.available.where(id: environment_ids) environments_found = environments.available
.where(id: environment_ids).to_a
if commit return environments_found unless commit
envs.select { |environment| env.includes_commit?(commit) }
else environments_found.select do |environment|
envs.select { |environment| env.recently_updated_on?(ref) } environment.includes_commit?(commit)
end
end
def environments_recently_updated_on_branch(branch)
environments_for(branch).select do |environment|
environment.recently_updated_on_branch?(branch)
end end
end end
......
...@@ -27,7 +27,8 @@ module Ci ...@@ -27,7 +27,8 @@ module Ci
end end
def environments def environments
@environments ||= project.environments_for(@ref) @environments ||= project
.environments_recently_updated_on_branch(@ref)
end end
end end
end end
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