Optimize Deployment#last_for_environment
Problem
In https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/22980/diffs#note_120036293 we discovered that Deployment#last_for_environment
is performing 2 queries to load deployments, this could be optimized to just one single query.
Furthermore, it seems like on the operations dashboard we would show failed or pending deployments instead of only the successful ones. @joshlambert & @sengelhard suggested that this should only include the successful ones
Proposal
- Prevent n+1 queries
- Filter the environments by status. Only return
success
ones.
Implementation proposal
- Remove
Deployment.last_for_environment
- Use
DeploymentPreloader
- Use
success
scope - See details
Edited by Halil Coban