Commit 15bfd724 authored by Thong Kuah's avatar Thong Kuah

Optimise query for #previous_environment_deployment

Rewrite to a much simpler query

- No need to search by name, unique index guarantees there can only be
one environment by that name for a project
- Also no need to have where claus for deployments.project_id. An
environment **must** belong to the same project_id anyway.
parent c1757f06
......@@ -251,11 +251,8 @@ class Deployment < ApplicationRecord
end
def previous_environment_deployment
project
.deployments
self.class.for_environment(environment_id)
.success
.joins(:environment)
.where(environments: { name: environment.name })
.where.not(id: self.id)
.order(id: :desc)
.take
......
---
title: Optimise query for Deployment#previous_environment_deployment in LinkMergeRequestWorker
merge_request: 57039
author:
type: performance
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