diff --git a/app/models/transaction/notification.rb b/app/models/transaction/notification.rb index 409bb6515..f6593a36f 100644 --- a/app/models/transaction/notification.rb +++ b/app/models/transaction/notification.rb @@ -51,7 +51,7 @@ class Transaction::Notification recipients_reason = {} # loop through all users - possible_recipients = User.group_access(ticket.group_id, 'full').sort_by(&:login) + possible_recipients = possible_recipients_of_group(ticket.group_id) # apply owner if ticket.owner_id != 1 @@ -347,4 +347,12 @@ class Transaction::Notification ) end + def possible_recipients_of_group(group_id) + cache = Cache.get("Transaction::Notification.group_access.full::#{group_id}") + return cache if cache + + possible_recipients = User.group_access(group_id, 'full').sort_by(&:login) + Cache.write("Transaction::Notification.group_access.full::#{group_id}", possible_recipients, expires_in: 20.seconds) + possible_recipients + end end diff --git a/test/unit/ticket_notification_test.rb b/test/unit/ticket_notification_test.rb index 1934dabe0..9b3c1b030 100644 --- a/test/unit/ticket_notification_test.rb +++ b/test/unit/ticket_notification_test.rb @@ -663,6 +663,8 @@ class TicketNotificationTest < ActiveSupport::TestCase @agent1.preferences['notification_config']['group_ids'] = ['-'] @agent2.save! + travel 1.minute # to skip loopup cache in Transaction::Notification + # create ticket in group ApplicationHandleInfo.current = 'scheduler.postmaster' ticket4 = Ticket.create!( @@ -727,6 +729,8 @@ class TicketNotificationTest < ActiveSupport::TestCase @agent2.preferences['notification_config']['group_ids'] = [99] @agent2.save! + travel 1.minute # to skip loopup cache in Transaction::Notification + # create ticket in group ApplicationHandleInfo.current = 'scheduler.postmaster' ticket5 = Ticket.create!( @@ -791,6 +795,8 @@ class TicketNotificationTest < ActiveSupport::TestCase @agent2.preferences['notification_config']['group_ids'] = [999] @agent2.save! + travel 1.minute # to skip loopup cache in Transaction::Notification + # create ticket in group ApplicationHandleInfo.current = 'scheduler.postmaster' ticket6 = Ticket.create!( @@ -868,6 +874,8 @@ class TicketNotificationTest < ActiveSupport::TestCase @agent2.preferences['notification_config']['group_ids'] = [999] @agent2.save! + travel 1.minute # to skip loopup cache in Transaction::Notification + # create ticket in group ApplicationHandleInfo.current = 'scheduler.postmaster' ticket7 = Ticket.create!(