summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-10-17 18:03:06 -0200
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-10-19 14:58:27 -0200
commit928acba4c0ae31626dac621f0f240f18cbad548a (patch)
tree2ef135225db8a550fd735647c002a2067f03270b
parent8379fbcd47930320bf4dd6a3ac41c6efd427a91a (diff)
downloadgitlab-ce-928acba4c0ae31626dac621f0f240f18cbad548a.tar.gz
Use keyword arguments on Sortable#highest_label_priority
-rw-r--r--app/models/concerns/issuable.rb11
-rw-r--r--app/models/concerns/sortable.rb8
-rw-r--r--app/models/todo.rb8
3 files changed, 19 insertions, 8 deletions
diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb
index d726cb6b7aa..245a865bcba 100644
--- a/app/models/concerns/issuable.rb
+++ b/app/models/concerns/issuable.rb
@@ -145,9 +145,14 @@ module Issuable
end
def order_labels_priority(excluded_labels: [])
- condition_field = "#{table_name}.id"
- project_field = "#{table_name}.project_id"
- highest_priority = highest_label_priority(name, project_field, condition_field, excluded_labels: excluded_labels).to_sql
+ params = {
+ target_type: name,
+ target_column: "#{table_name}.id",
+ project_column: "#{table_name}.project_id",
+ excluded_labels: excluded_labels
+ }
+
+ highest_priority = highest_label_priority(params).to_sql
select("#{table_name}.*, (#{highest_priority}) AS highest_priority").
group(arel_table[:id]).
diff --git a/app/models/concerns/sortable.rb b/app/models/concerns/sortable.rb
index 83e551fd152..12b23f00769 100644
--- a/app/models/concerns/sortable.rb
+++ b/app/models/concerns/sortable.rb
@@ -38,13 +38,13 @@ module Sortable
private
- def highest_label_priority(object_types, project_field, condition_field, excluded_labels: [])
+ def highest_label_priority(target_type:, target_column:, project_column:, excluded_labels: [])
query = Label.select(LabelPriority.arel_table[:priority].minimum).
left_join_priorities.
joins(:label_links).
- where(label_links: { target_type: object_types }).
- where("label_priorities.project_id = #{project_field}").
- where("label_links.target_id = #{condition_field}").
+ 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?
diff --git a/app/models/todo.rb b/app/models/todo.rb
index fd90a893d2e..11c072dd000 100644
--- a/app/models/todo.rb
+++ b/app/models/todo.rb
@@ -52,7 +52,13 @@ class Todo < ActiveRecord::Base
# Todos with highest priority first then oldest todos
# 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
- highest_priority = highest_label_priority(["Issue", "MergeRequest"], "todos.project_id", "todos.target_id").to_sql
+ params = {
+ target_type: ['Issue', 'MergeRequest'],
+ target_column: "todos.target_id",
+ project_column: "todos.project_id"
+ }
+
+ highest_priority = highest_label_priority(params).to_sql
select("#{table_name}.*, (#{highest_priority}) AS highest_priority").
order(Gitlab::Database.nulls_last_order('highest_priority', 'ASC')).