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
|
||||
taskbar = Taskbar.find(params[:id])
|
||||
access(taskbar)
|
||||
taskbar.with_lock do
|
||||
taskbar.update_attributes!(Taskbar.param_cleanup(params))
|
||||
end
|
||||
model_update_render_item(taskbar)
|
||||
end
|
||||
|
||||
def destroy
|
||||
taskbar = Taskbar.find(params[:id])
|
||||
access(taskbar)
|
||||
taskbar.with_lock do
|
||||
taskbar.destroy
|
||||
end
|
||||
model_destroy_render_item()
|
||||
end
|
||||
|
||||
|
|
|
@ -24,11 +24,19 @@ class Observer::Organization::RefObjectTouch < ActiveRecord::Observer
|
|||
return if User.where(organization_id: record.id).count > 100
|
||||
|
||||
# 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
|
||||
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
|
||||
|
|
|
@ -88,9 +88,11 @@ class Taskbar < ApplicationModel
|
|||
# update other taskbars
|
||||
Taskbar.where(key: key).order(:created_at, :id).each { |taskbar|
|
||||
next if taskbar.id == id
|
||||
taskbar.with_lock do
|
||||
taskbar.preferences = preferences
|
||||
taskbar.local_update = true
|
||||
taskbar.save!
|
||||
end
|
||||
}
|
||||
|
||||
return true if destroyed?
|
||||
|
|
Loading…
Reference in a new issue