summaryrefslogtreecommitdiff
path: root/app/models/deployment.rb
diff options
context:
space:
mode:
authorTimothy Andrew <mail@timothyandrew.net>2016-09-20 18:13:11 +0530
committerTimothy Andrew <mail@timothyandrew.net>2016-09-20 18:13:11 +0530
commit71d4bf721be6cd57ab3480bc5efb11a91d6e1891 (patch)
tree81b567b59729128e38121f4bb7286383945aa99b /app/models/deployment.rb
parent6f194e28e4fd8380432420b2b525b134ddb18a3d (diff)
downloadgitlab-ce-71d4bf721be6cd57ab3480bc5efb11a91d6e1891.tar.gz
Implement (some) comments from @DouweM's review.
- Move things common to `Issue` and `MergeRequest` into `Issuable` - Move more database-specific functions into `Gitlab::Database` - Indentation changes and other minor refactorings.
Diffstat (limited to 'app/models/deployment.rb')
-rw-r--r--app/models/deployment.rb23
1 files changed, 10 insertions, 13 deletions
diff --git a/app/models/deployment.rb b/app/models/deployment.rb
index 183d538a867..31a5bb1f962 100644
--- a/app/models/deployment.rb
+++ b/app/models/deployment.rb
@@ -46,22 +46,19 @@ class Deployment < ActiveRecord::Base
def update_merge_request_metrics
if environment.update_merge_request_metrics?
- query = project.merge_requests.
- joins(:metrics).
- where(target_branch: self.ref, merge_request_metrics: { first_deployed_to_production_at: nil })
-
- merge_requests =
- if previous_deployment
- query.where("merge_request_metrics.merged_at <= ? AND merge_request_metrics.merged_at >= ?",
- self.created_at,
- previous_deployment.created_at)
- else
- query.where("merge_request_metrics.merged_at <= ?", self.created_at)
- end
+ merge_requests = project.merge_requests.
+ joins(:metrics).
+ where(target_branch: self.ref, merge_request_metrics: { first_deployed_to_production_at: nil }).
+ where("merge_request_metrics.merged_at <= ?", self.created_at)
+
+ if previous_deployment
+ merge_requests = merge_requests.where("merge_request_metrics.merged_at >= ?", previous_deployment.created_at)
+ end
# Need to use `map` instead of `select` because MySQL doesn't allow `SELECT`ing from the same table
# that we're updating.
- MergeRequest::Metrics.where(merge_request_id: merge_requests.map(&:id), first_deployed_to_production_at: nil).
+ MergeRequest::Metrics.
+ where(merge_request_id: merge_requests.map(&:id), first_deployed_to_production_at: nil).
update_all(first_deployed_to_production_at: self.created_at)
end
end