summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-10-28 11:50:43 +0000
committerStan Hu <stanhu@gmail.com>2016-10-28 23:26:08 -0700
commitef037519673c5619319793fbe922849b3ca1369b (patch)
tree18ffe107253ebdc51b4a6fda60a16f03d4ff6756 /app
parentd31fa260d067bbdb1e3b6c82bbf1c01a5f66f54d (diff)
downloadgitlab-ce-ef037519673c5619319793fbe922849b3ca1369b.tar.gz
Merge branch '23928-sortable-highest_label_priority-is-bugged' into 'master'
Fix and improve `Sortable.highest_label_priority` Closes #23928 See merge request !7165
Diffstat (limited to 'app')
-rw-r--r--app/models/concerns/sortable.rb11
-rw-r--r--app/models/todo.rb2
2 files changed, 9 insertions, 4 deletions
diff --git a/app/models/concerns/sortable.rb b/app/models/concerns/sortable.rb
index 12b23f00769..7edb0acd56c 100644
--- a/app/models/concerns/sortable.rb
+++ b/app/models/concerns/sortable.rb
@@ -38,16 +38,21 @@ module Sortable
private
- def highest_label_priority(target_type:, target_column:, project_column:, excluded_labels: [])
+ def highest_label_priority(target_type_column: nil, target_type: nil, target_column:, project_column:, excluded_labels: [])
query = Label.select(LabelPriority.arel_table[:priority].minimum).
left_join_priorities.
joins(:label_links).
where("label_priorities.project_id = #{project_column}").
- where(label_links: { target_type: target_type }).
where("label_links.target_id = #{target_column}").
reorder(nil)
- query.where.not(title: excluded_labels) if excluded_labels.present?
+ if target_type_column
+ query = query.where("label_links.target_type = #{target_type_column}")
+ else
+ query = query.where(label_links: { target_type: target_type })
+ end
+
+ query = query.where.not(title: excluded_labels) if excluded_labels.present?
query
end
diff --git a/app/models/todo.rb b/app/models/todo.rb
index 11c072dd000..f5ade1cc293 100644
--- a/app/models/todo.rb
+++ b/app/models/todo.rb
@@ -53,7 +53,7 @@ class Todo < ActiveRecord::Base
# Need to order by created_at last because of differences on Mysql and Postgres when joining by type "Merge_request/Issue"
def order_by_labels_priority
params = {
- target_type: ['Issue', 'MergeRequest'],
+ target_type_column: "todos.target_type",
target_column: "todos.target_id",
project_column: "todos.project_id"
}