Last active
April 25, 2017 09:35
-
-
Save somebody32/11cc80527fd9bf35c059917afb7d4856 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ActiveRecord::Base.transaction do | |
- # doing delete ... where task_id in (...) and subtask_id is null (inequality test on secondary key), | |
- # locks secondary indexes and primary key index | |
- AssignedUser.where(task_id: task.id, subtask_id: nil).delete_all | |
+ assigned_user_ids_to_clean = AssignedUser.where(task_id: task.id, subtask_id: nil).pluck(:id) | |
+ # doing delete ... where id in (...) (equality test on primary key), locks only primary key index | |
+ AssignedUser.where(id: assigned_user_ids_to_clean).delete_all | |
task.assigned_user_ids = assigned_user_ids # inserts multiple records | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment