diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-12 21:08:48 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-12 21:08:48 +0000 |
commit | 006e89697dd5165f355afc20fc6bb0cdfa7b381a (patch) | |
tree | 9095aeb37b2c80f3b0cc5a8dfd27baf93f05b61b /app/models/concerns/issuable.rb | |
parent | 43e3dc2f95a25c600e08f65d4f1c406a1a63ed3d (diff) | |
download | gitlab-ce-006e89697dd5165f355afc20fc6bb0cdfa7b381a.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/concerns/issuable.rb')
-rw-r--r-- | app/models/concerns/issuable.rb | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index a6961df1b51..f3e03ed22d7 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -249,7 +249,7 @@ module Issuable Gitlab::Database.nulls_last_order('highest_priority', direction)) end - def order_labels_priority(direction = 'ASC', excluded_labels: [], extra_select_columns: []) + def order_labels_priority(direction = 'ASC', excluded_labels: [], extra_select_columns: [], with_cte: false) params = { target_type: name, target_column: "#{table_name}.id", @@ -265,7 +265,7 @@ module Issuable ] + extra_select_columns select(select_columns.join(', ')) - .group(arel_table[:id]) + .group(issue_grouping_columns(use_cte: with_cte)) .reorder(Gitlab::Database.nulls_last_order('highest_priority', direction)) end @@ -294,6 +294,18 @@ module Issuable grouping_columns end + # Includes all table keys in group by clause when sorting + # preventing errors in postgres when using CTE search optimisation + # + # Returns an array of arel columns + def issue_grouping_columns(use_cte: false) + if use_cte + [arel_table[:state]] + attribute_names.map { |attr| arel_table[attr.to_sym] } + else + arel_table[:id] + end + end + def to_ability_name model_name.singular end |