Prevent database dead locks.
This commit is contained in:
parent
14711a6826
commit
f35645e051
3 changed files with 21 additions and 7 deletions
|
@ -21,14 +21,18 @@ class TaskbarController < ApplicationController
|
||||||
def update
|
def update
|
||||||
taskbar = Taskbar.find(params[:id])
|
taskbar = Taskbar.find(params[:id])
|
||||||
access(taskbar)
|
access(taskbar)
|
||||||
|
taskbar.with_lock do
|
||||||
taskbar.update_attributes!(Taskbar.param_cleanup(params))
|
taskbar.update_attributes!(Taskbar.param_cleanup(params))
|
||||||
|
end
|
||||||
model_update_render_item(taskbar)
|
model_update_render_item(taskbar)
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
taskbar = Taskbar.find(params[:id])
|
taskbar = Taskbar.find(params[:id])
|
||||||
access(taskbar)
|
access(taskbar)
|
||||||
|
taskbar.with_lock do
|
||||||
taskbar.destroy
|
taskbar.destroy
|
||||||
|
end
|
||||||
model_destroy_render_item()
|
model_destroy_render_item()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -24,11 +24,19 @@ class Observer::Organization::RefObjectTouch < ActiveRecord::Observer
|
||||||
return if User.where(organization_id: record.id).count > 100
|
return if User.where(organization_id: record.id).count > 100
|
||||||
|
|
||||||
# touch organizations tickets
|
# touch organizations tickets
|
||||||
Ticket.select('id').where(organization_id: record.id).each(&:touch)
|
Ticket.select('id').where(organization_id: record.id).pluck(:id).each { |ticket_id|
|
||||||
|
ticket = Ticket.find(ticket_id)
|
||||||
|
ticket.with_lock do
|
||||||
|
ticket.touch
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
# touch current members
|
# touch current members
|
||||||
record.member_ids.uniq.each { |user_id|
|
record.member_ids.uniq.each { |user_id|
|
||||||
User.find(user_id).touch
|
user = User.find(user_id)
|
||||||
|
user.with_lock do
|
||||||
|
user.touch
|
||||||
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -88,9 +88,11 @@ class Taskbar < ApplicationModel
|
||||||
# update other taskbars
|
# update other taskbars
|
||||||
Taskbar.where(key: key).order(:created_at, :id).each { |taskbar|
|
Taskbar.where(key: key).order(:created_at, :id).each { |taskbar|
|
||||||
next if taskbar.id == id
|
next if taskbar.id == id
|
||||||
|
taskbar.with_lock do
|
||||||
taskbar.preferences = preferences
|
taskbar.preferences = preferences
|
||||||
taskbar.local_update = true
|
taskbar.local_update = true
|
||||||
taskbar.save!
|
taskbar.save!
|
||||||
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
return true if destroyed?
|
return true if destroyed?
|
||||||
|
|
Loading…
Reference in a new issue