diff --git a/app/models/application_model/has_cache.rb b/app/models/application_model/has_cache.rb index 9a6f285dc..3da88c972 100644 --- a/app/models/application_model/has_cache.rb +++ b/app/models/application_model/has_cache.rb @@ -4,11 +4,7 @@ module ApplicationModel::HasCache included do before_create :cache_delete - - after_create :cache_delete - after_update :cache_delete - after_touch :cache_delete - after_destroy :cache_delete + after_commit :cache_delete end def cache_update(other) diff --git a/app/models/observer/transaction.rb b/app/models/observer/transaction.rb index 68c7cabf5..648e1ee7d 100644 --- a/app/models/observer/transaction.rb +++ b/app/models/observer/transaction.rb @@ -120,12 +120,12 @@ class Observer::Transaction < ActiveRecord::Observer # simulate article create as ticket update article = nil 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 event[:type] == 'update' # set new event infos - ticket = Ticket.lookup(id: article.ticket_id) + ticket = Ticket.find_by(id: article.ticket_id) event[:object] = 'Ticket' event[:id] = ticket.id event[:type] = 'update' @@ -133,7 +133,7 @@ class Observer::Transaction < ActiveRecord::Observer end # 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 diff --git a/app/models/ticket.rb b/app/models/ticket.rb index a1f4777ef..49c1179a9 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -591,7 +591,7 @@ condition example 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 query += "#{attribute} IN (?)" - user = User.lookup(id: current_user_id) + user = User.find_by(id: current_user_id) bind_params.push user.organization_id else # rubocop:disable Style/IfInsideElse @@ -624,7 +624,7 @@ condition example end elsif selector['pre_condition'] == 'current_user.organization_id' 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 else # rubocop:disable Style/IfInsideElse @@ -807,7 +807,7 @@ perform changes on ticket logger.debug { "Perform #{perform_origin} #{perform.inspect} on Ticket.find(#{id})" } article = begin - Ticket::Article.lookup(id: item.try(:dig, :article_id)) + Ticket::Article.find_by(id: item.try(:dig, :article_id)) rescue ArgumentError nil end @@ -847,18 +847,18 @@ perform changes on ticket elsif article.from.present? recipients_raw.push(article.from) 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) 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) end end elsif recipient == 'ticket_customer' - email = User.lookup(id: customer_id).email + email = User.find_by(id: customer_id).email recipients_raw.push(email) elsif recipient == 'ticket_owner' - email = User.lookup(id: owner_id).email + email = User.find_by(id: owner_id).email recipients_raw.push(email) elsif recipient == 'ticket_agents' User.group_access(group_id, 'full').sort_by(&:login).each do |user| diff --git a/app/models/transaction/trigger.rb b/app/models/transaction/trigger.rb index 0cda993b2..5faab763d 100644 --- a/app/models/transaction/trigger.rb +++ b/app/models/transaction/trigger.rb @@ -29,10 +29,10 @@ class Transaction::Trigger return if @item[:object] != 'Ticket' - ticket = Ticket.lookup(id: @item[:object_id]) + ticket = Ticket.find_by(id: @item[:object_id]) return if !ticket if @item[:article_id] - article = Ticket::Article.lookup(id: @item[:article_id]) + article = Ticket::Article.find_by(id: @item[:article_id]) end original_user_id = UserInfo.current_user_id diff --git a/app/models/user_group.rb b/app/models/user_group.rb index d7419c2da..b1d473764 100644 --- a/app/models/user_group.rb +++ b/app/models/user_group.rb @@ -19,7 +19,7 @@ class UserGroup < ApplicationModel def cache_delete group.cache_update(nil) - user.cache_update(nil) + user.cache_update(nil) if user.present? super end