Skip to content

Commit

Permalink
Fix race condition when updating competition tabs order.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatanklosko committed Aug 3, 2019
1 parent e5a9bcb commit b6aaffa
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions WcaOnRails/app/models/competition_tab.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ def reorder(direction)
other_display_order = display_order + (direction.to_s == "up" ? -1 : 1) other_display_order = display_order + (direction.to_s == "up" ? -1 : 1)
other_tab = competition.tabs.find_by(display_order: other_display_order) other_tab = competition.tabs.find_by(display_order: other_display_order)
if other_tab if other_tab
update_column :display_order, nil ActiveRecord::Base.transaction do
other_tab.update_column :display_order, current_display_order update_column :display_order, nil
update_column :display_order, other_display_order other_tab.update_column :display_order, current_display_order
update_column :display_order, other_display_order
end
end end
end end
end end

0 comments on commit b6aaffa

Please sign in to comment.