diff options
Diffstat (limited to 'app/models/milestone.rb')
-rw-r--r-- | app/models/milestone.rb | 42 |
1 files changed, 5 insertions, 37 deletions
diff --git a/app/models/milestone.rb b/app/models/milestone.rb index b04bed4c014..d2e2749f70d 100644 --- a/app/models/milestone.rb +++ b/app/models/milestone.rb @@ -98,11 +98,11 @@ class Milestone < ActiveRecord::Base if Gitlab::Database.postgresql? rel.order(:project_id, :due_date).select('DISTINCT ON (project_id) id') else - rel. - group(:project_id). - having('due_date = MIN(due_date)'). - pluck(:id, :project_id, :due_date). - map(&:first) + rel + .group(:project_id) + .having('due_date = MIN(due_date)') + .pluck(:id, :project_id, :due_date) + .map(&:first) end end @@ -164,38 +164,6 @@ class Milestone < ActiveRecord::Base write_attribute(:title, sanitize_title(value)) if value.present? end - # Sorts the issues for the given IDs. - # - # This method runs a single SQL query using a CASE statement to update the - # position of all issues in the current milestone (scoped to the list of IDs). - # - # Given the ids [10, 20, 30] this method produces a SQL query something like - # the following: - # - # UPDATE issues - # SET position = CASE - # WHEN id = 10 THEN 1 - # WHEN id = 20 THEN 2 - # WHEN id = 30 THEN 3 - # ELSE position - # END - # WHERE id IN (10, 20, 30); - # - # This method expects that the IDs given in `ids` are already Fixnums. - def sort_issues(ids) - pairs = [] - - ids.each_with_index do |id, index| - pairs << id - pairs << index + 1 - end - - conditions = 'WHEN id = ? THEN ? ' * ids.length - - issues.where(id: ids). - update_all(["position = CASE #{conditions} ELSE position END", *pairs]) - end - private def milestone_format_reference(format = :iid) |