Avoid an extra a query per label when setting label priority

parent b10e5764
...@@ -97,8 +97,9 @@ class Projects::LabelsController < Projects::ApplicationController ...@@ -97,8 +97,9 @@ class Projects::LabelsController < Projects::ApplicationController
def set_priorities def set_priorities
Label.transaction do Label.transaction do
params[:label_ids].each_with_index do |label_id, index| params[:label_ids].each_with_index do |label_id, index|
label = labels.find_by_id(label_id) next unless labels.where(id: label_id).any?
label.update_attribute(:priority, index) if label
Label.where(id: label_id).update_all(priority: index)
end end
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