diff --git a/app/models/observer/ticket/notification.rb b/app/models/observer/ticket/notification.rb index 4c8611990..dab86a86e 100644 --- a/app/models/observer/ticket/notification.rb +++ b/app/models/observer/ticket/notification.rb @@ -12,10 +12,10 @@ class Observer::Ticket::Notification < ActiveRecord::Observer return if Setting.get('import_mode') # get buffer - list = EventBuffer.list + list = EventBuffer.list('notification') # reset buffer - EventBuffer.reset + EventBuffer.reset('notification') via_web = false if ENV['RACK_ENV'] || Rails.configuration.webserver_is_active @@ -36,17 +36,29 @@ class Observer::Ticket::Notification < ActiveRecord::Observer result = get_uniq_changes(events) result = { - :1 => { - :type => 'create', - :ticket_id => 123, - :article_id => 123, + 1 => { + type: 'create', + ticket_id: 123, + article_id: 123, }, - :9 = { - :type => 'update', - :ticket_id => 123, - :changes => { - :attribute1 => [before,now], - :attribute2 => [before,now], + 9 => { + type: 'update', + ticket_id: 123, + changes: { + attribute1: [before, now], + attribute2: [before, now], + } + }, + } + + result = { + 9 => { + type: 'update', + ticket_id: 123, + article_id: 123, + changes: { + attribute1: [before, now], + attribute2: [before, now], } }, } @@ -124,7 +136,7 @@ class Observer::Ticket::Notification < ActiveRecord::Observer data: record, id: record.id, } - EventBuffer.add(e) + EventBuffer.add('notification', e) end def before_update(record) @@ -160,18 +172,7 @@ class Observer::Ticket::Notification < ActiveRecord::Observer changes: real_changes, id: record.id, } - EventBuffer.add(e) + EventBuffer.add('notification', e) end - def after_update(_record) - - # return if we run import mode - return if Setting.get('import_mode') - - # Rails.logger.info 'after_update' - # Rails.logger.info record.inspect - # Rails.logger.info '-----' - # Rails.logger.info @a.inspect - # AuditTrail.new(record, "UPDATED") - end end diff --git a/lib/event_buffer.rb b/lib/event_buffer.rb index 1e3e09ed5..95dc34095 100644 --- a/lib/event_buffer.rb +++ b/lib/event_buffer.rb @@ -1,18 +1,26 @@ module EventBuffer - def self.list - Thread.current[:event_buffer] || [] - end - - def self.add(item) + def self.list(key) if !Thread.current[:event_buffer] - Thread.current[:event_buffer] = [] + Thread.current[:event_buffer] = {} end - Thread.current[:event_buffer].push item + Thread.current[:event_buffer][key] || [] end - def self.reset - Thread.current[:event_buffer] = [] + def self.add(key, item) + if !Thread.current[:event_buffer] + Thread.current[:event_buffer] = {} + end + if !Thread.current[:event_buffer][key] + Thread.current[:event_buffer][key] = [] + end + Thread.current[:event_buffer][key].push item + end + + def self.reset(key) + return if !Thread.current[:event_buffer] + return if !Thread.current[:event_buffer][key] + Thread.current[:event_buffer][key] = [] end end