Migrated after_* callbacks to after_commit to avoid race conditions between cache creation and database insert/update. See: http://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html\#module-ActiveRecord::Transactions::ClassMethods-label-Callbacks .
This commit is contained in:
parent
809a698c03
commit
11e63fe21a
5 changed files with 14 additions and 18 deletions
|
@ -4,11 +4,7 @@ module ApplicationModel::HasCache
|
||||||
|
|
||||||
included do
|
included do
|
||||||
before_create :cache_delete
|
before_create :cache_delete
|
||||||
|
after_commit :cache_delete
|
||||||
after_create :cache_delete
|
|
||||||
after_update :cache_delete
|
|
||||||
after_touch :cache_delete
|
|
||||||
after_destroy :cache_delete
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def cache_update(other)
|
def cache_update(other)
|
||||||
|
|
|
@ -120,12 +120,12 @@ class Observer::Transaction < ActiveRecord::Observer
|
||||||
# simulate article create as ticket update
|
# simulate article create as ticket update
|
||||||
article = nil
|
article = nil
|
||||||
if event[:object] == 'Ticket::Article'
|
if event[:object] == 'Ticket::Article'
|
||||||
article = Ticket::Article.lookup(id: event[:id])
|
article = Ticket::Article.find_by(id: event[:id])
|
||||||
next if !article
|
next if !article
|
||||||
next if event[:type] == 'update'
|
next if event[:type] == 'update'
|
||||||
|
|
||||||
# set new event infos
|
# set new event infos
|
||||||
ticket = Ticket.lookup(id: article.ticket_id)
|
ticket = Ticket.find_by(id: article.ticket_id)
|
||||||
event[:object] = 'Ticket'
|
event[:object] = 'Ticket'
|
||||||
event[:id] = ticket.id
|
event[:id] = ticket.id
|
||||||
event[:type] = 'update'
|
event[:type] = 'update'
|
||||||
|
@ -133,7 +133,7 @@ class Observer::Transaction < ActiveRecord::Observer
|
||||||
end
|
end
|
||||||
|
|
||||||
# get current state of objects
|
# get current state of objects
|
||||||
object = Kernel.const_get(event[:object]).lookup(id: event[:id])
|
object = Kernel.const_get(event[:object]).find_by(id: event[:id])
|
||||||
|
|
||||||
# next if object is already deleted
|
# next if object is already deleted
|
||||||
next if !object
|
next if !object
|
||||||
|
|
|
@ -591,7 +591,7 @@ condition example
|
||||||
elsif selector['pre_condition'] == 'current_user.organization_id'
|
elsif selector['pre_condition'] == 'current_user.organization_id'
|
||||||
raise "Use current_user.id in selector, but no current_user is set #{selector.inspect}" if !current_user_id
|
raise "Use current_user.id in selector, but no current_user is set #{selector.inspect}" if !current_user_id
|
||||||
query += "#{attribute} IN (?)"
|
query += "#{attribute} IN (?)"
|
||||||
user = User.lookup(id: current_user_id)
|
user = User.find_by(id: current_user_id)
|
||||||
bind_params.push user.organization_id
|
bind_params.push user.organization_id
|
||||||
else
|
else
|
||||||
# rubocop:disable Style/IfInsideElse
|
# rubocop:disable Style/IfInsideElse
|
||||||
|
@ -624,7 +624,7 @@ condition example
|
||||||
end
|
end
|
||||||
elsif selector['pre_condition'] == 'current_user.organization_id'
|
elsif selector['pre_condition'] == 'current_user.organization_id'
|
||||||
query += "#{attribute} NOT IN (?)"
|
query += "#{attribute} NOT IN (?)"
|
||||||
user = User.lookup(id: current_user_id)
|
user = User.find_by(id: current_user_id)
|
||||||
bind_params.push user.organization_id
|
bind_params.push user.organization_id
|
||||||
else
|
else
|
||||||
# rubocop:disable Style/IfInsideElse
|
# rubocop:disable Style/IfInsideElse
|
||||||
|
@ -807,7 +807,7 @@ perform changes on ticket
|
||||||
logger.debug { "Perform #{perform_origin} #{perform.inspect} on Ticket.find(#{id})" }
|
logger.debug { "Perform #{perform_origin} #{perform.inspect} on Ticket.find(#{id})" }
|
||||||
|
|
||||||
article = begin
|
article = begin
|
||||||
Ticket::Article.lookup(id: item.try(:dig, :article_id))
|
Ticket::Article.find_by(id: item.try(:dig, :article_id))
|
||||||
rescue ArgumentError
|
rescue ArgumentError
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
@ -847,18 +847,18 @@ perform changes on ticket
|
||||||
elsif article.from.present?
|
elsif article.from.present?
|
||||||
recipients_raw.push(article.from)
|
recipients_raw.push(article.from)
|
||||||
elsif article.origin_by_id
|
elsif article.origin_by_id
|
||||||
email = User.lookup(id: article.origin_by_id).email
|
email = User.find_by(id: article.origin_by_id).email
|
||||||
recipients_raw.push(email)
|
recipients_raw.push(email)
|
||||||
elsif article.created_by_id
|
elsif article.created_by_id
|
||||||
email = User.lookup(id: article.created_by_id).email
|
email = User.find_by(id: article.created_by_id).email
|
||||||
recipients_raw.push(email)
|
recipients_raw.push(email)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elsif recipient == 'ticket_customer'
|
elsif recipient == 'ticket_customer'
|
||||||
email = User.lookup(id: customer_id).email
|
email = User.find_by(id: customer_id).email
|
||||||
recipients_raw.push(email)
|
recipients_raw.push(email)
|
||||||
elsif recipient == 'ticket_owner'
|
elsif recipient == 'ticket_owner'
|
||||||
email = User.lookup(id: owner_id).email
|
email = User.find_by(id: owner_id).email
|
||||||
recipients_raw.push(email)
|
recipients_raw.push(email)
|
||||||
elsif recipient == 'ticket_agents'
|
elsif recipient == 'ticket_agents'
|
||||||
User.group_access(group_id, 'full').sort_by(&:login).each do |user|
|
User.group_access(group_id, 'full').sort_by(&:login).each do |user|
|
||||||
|
|
|
@ -29,10 +29,10 @@ class Transaction::Trigger
|
||||||
|
|
||||||
return if @item[:object] != 'Ticket'
|
return if @item[:object] != 'Ticket'
|
||||||
|
|
||||||
ticket = Ticket.lookup(id: @item[:object_id])
|
ticket = Ticket.find_by(id: @item[:object_id])
|
||||||
return if !ticket
|
return if !ticket
|
||||||
if @item[:article_id]
|
if @item[:article_id]
|
||||||
article = Ticket::Article.lookup(id: @item[:article_id])
|
article = Ticket::Article.find_by(id: @item[:article_id])
|
||||||
end
|
end
|
||||||
|
|
||||||
original_user_id = UserInfo.current_user_id
|
original_user_id = UserInfo.current_user_id
|
||||||
|
|
|
@ -19,7 +19,7 @@ class UserGroup < ApplicationModel
|
||||||
|
|
||||||
def cache_delete
|
def cache_delete
|
||||||
group.cache_update(nil)
|
group.cache_update(nil)
|
||||||
user.cache_update(nil)
|
user.cache_update(nil) if user.present?
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue