Move permission check before more expensive checks

This commit is contained in:
Douwe Maan 2017-02-07 11:43:36 -06:00
parent 5dc3b37b86
commit 0fdf54ddf5
1 changed files with 5 additions and 3 deletions

View File

@ -24,6 +24,10 @@ class EnvironmentsFinder
environments = project.environments.available
.where(id: environment_ids).order_by_last_deployed_at.to_a
environments.select! do |environment|
Ability.allowed?(current_user, :read_environment, environment)
end
if ref && commit
environments.select! do |environment|
environment.includes_commit?(commit)
@ -36,9 +40,7 @@ class EnvironmentsFinder
end
end
environments.select do |environment|
Ability.allowed?(current_user, :read_environment, environment)
end
environments
end
private