Feature #17460 » mysql5.7_deadlocks_fix.patch
| lib/redmine/nested_set/issue_nested_set.rb (working copy) | ||
|---|---|---|
|
end
|
||
|
|
||
|
def lock_nested_set
|
||
|
if self.class.connection.adapter_name =~ /sqlserver/i
|
||
|
lock = "WITH (ROWLOCK HOLDLOCK UPDLOCK)"
|
||
|
# Custom lock for SQLServer
|
||
|
if Redmine::Database.postgresql?
|
||
|
sets_to_lock = [id, parent_id].compact
|
||
|
self.class.reorder(:id).where("root_id IN (SELECT root_id FROM #{self.class.table_name} WHERE id IN (?))", sets_to_lock).lock.ids
|
||
|
else
|
||
|
lock = true
|
||
|
# This can be problematic if root_id or parent root_id changes
|
||
|
# before locking
|
||
|
sets_to_lock = [root_id, parent.try(:root_id)].compact.uniq
|
||
|
self.class.reorder(:id).where(:root_id => sets_to_lock).lock(lock).ids
|
||
|
else
|
||
|
sets_to_lock = [id, parent_id].compact
|
||
|
self.class.reorder(:id).where("root_id IN (SELECT root_id FROM #{self.class.table_name} WHERE id IN (?))", sets_to_lock).lock.ids
|
||
|
if self.class.connection.adapter_name =~ /sqlserver/i
|
||
|
# Custom lock for SQLServer
|
||
|
lock = "WITH (ROWLOCK HOLDLOCK UPDLOCK)"
|
||
|
end
|
||
|
# No need to instanciate records
|
||
|
self.class.connection.execute(self.class.reorder(:id).where(:root_id => sets_to_lock).lock.to_sql)
|
||
|
end
|
||
|
end
|
||
|
|
||