Prevent database dead locks.

This commit is contained in:
Martin Edenhofer 2017-08-22 19:36:48 +02:00
parent 14711a6826
commit f35645e051
3 changed files with 21 additions and 7 deletions

View file

@ -21,14 +21,18 @@ class TaskbarController < ApplicationController
def update
taskbar = Taskbar.find(params[:id])
access(taskbar)
taskbar.update_attributes!(Taskbar.param_cleanup(params))
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.destroy
taskbar.with_lock do
taskbar.destroy
end
model_destroy_render_item()
end

View file

@ -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

View file

@ -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.preferences = preferences
taskbar.local_update = true
taskbar.save!
taskbar.with_lock do
taskbar.preferences = preferences
taskbar.local_update = true
taskbar.save!
end
}
return true if destroyed?