Commit 7cf73994 authored by Pavel Shutsin's avatar Pavel Shutsin

Fix productivity analytics listing with multiple labels

parent c53477fa
---
title: Fix productivity analytics listing with multiple labels
merge_request: 33182
author:
type: fixed
...@@ -43,28 +43,36 @@ class ProductivityAnalytics ...@@ -43,28 +43,36 @@ class ProductivityAnalytics
end end
columns.unshift(MergeRequest.arel_table[Arel.star]) columns.unshift(MergeRequest.arel_table[Arel.star])
mrs = merge_requests.select(columns) MergeRequest.joins(:metrics).select(columns).where(id: merge_requests).order(sorting)
mrs = mrs.reorder(custom_sorting) if custom_sorting
mrs
end end
private private
def histogram_query(column) def histogram_query(column)
merge_requests.except(:select).select("#{column} as metric, count(*) as mr_count").group(column).reorder(nil) MergeRequest::Metrics.joins(:merge_request)
.where(merge_request_id: merge_requests)
.select("#{column} as metric, count(*) as mr_count")
.group(column)
end end
def scatterplot_query(column) def scatterplot_query(column)
merge_requests.except(:select).select("#{column} as metric, merge_requests.id, merge_request_metrics.merged_at").reorder("merge_request_metrics.merged_at ASC") merge_requests
.except(:select)
.select("#{column} as metric, merge_requests.id, merge_request_metrics.merged_at")
.reorder("merge_request_metrics.merged_at ASC")
end end
def custom_sorting def sorting
return unless sort return default_sorting unless sort
column, direction = sort.split(/_(asc|desc)$/i) column, direction = sort.split(/_(asc|desc)$/i)
return unless column.in?(METRIC_TYPES) return default_sorting unless column.in?(METRIC_TYPES)
Arel.sql("#{column} #{direction}") Arel.sql("#{column} #{direction}")
end end
def default_sorting
{id: :desc}
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