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
end
columns.unshift(MergeRequest.arel_table[Arel.star])
mrs = merge_requests.select(columns)
mrs = mrs.reorder(custom_sorting) if custom_sorting
mrs
MergeRequest.joins(:metrics).select(columns).where(id: merge_requests).order(sorting)
end
private
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
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
def custom_sorting
return unless sort
def sorting
return default_sorting unless sort
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}")
end
def default_sorting
{id: :desc}
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