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