Performance: When many tickets have reached the reminder or are escalated (more than 1400) processing of those causes a high CPU load and long blocking of background processing. Caching Group permission lookup for users reduces this load.

This commit is contained in:
Martin Edenhofer 2019-10-04 11:42:44 +02:00 committed by Thorsten Eckel
parent 4182b0b567
commit f57f0486a3
2 changed files with 17 additions and 1 deletions

View file

@ -51,7 +51,7 @@ class Transaction::Notification
recipients_reason = {} recipients_reason = {}
# loop through all users # 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 # apply owner
if ticket.owner_id != 1 if ticket.owner_id != 1
@ -347,4 +347,12 @@ class Transaction::Notification
) )
end 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 end

View file

@ -663,6 +663,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
@agent1.preferences['notification_config']['group_ids'] = ['-'] @agent1.preferences['notification_config']['group_ids'] = ['-']
@agent2.save! @agent2.save!
travel 1.minute # to skip loopup cache in Transaction::Notification
# create ticket in group # create ticket in group
ApplicationHandleInfo.current = 'scheduler.postmaster' ApplicationHandleInfo.current = 'scheduler.postmaster'
ticket4 = Ticket.create!( ticket4 = Ticket.create!(
@ -727,6 +729,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
@agent2.preferences['notification_config']['group_ids'] = [99] @agent2.preferences['notification_config']['group_ids'] = [99]
@agent2.save! @agent2.save!
travel 1.minute # to skip loopup cache in Transaction::Notification
# create ticket in group # create ticket in group
ApplicationHandleInfo.current = 'scheduler.postmaster' ApplicationHandleInfo.current = 'scheduler.postmaster'
ticket5 = Ticket.create!( ticket5 = Ticket.create!(
@ -791,6 +795,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
@agent2.preferences['notification_config']['group_ids'] = [999] @agent2.preferences['notification_config']['group_ids'] = [999]
@agent2.save! @agent2.save!
travel 1.minute # to skip loopup cache in Transaction::Notification
# create ticket in group # create ticket in group
ApplicationHandleInfo.current = 'scheduler.postmaster' ApplicationHandleInfo.current = 'scheduler.postmaster'
ticket6 = Ticket.create!( ticket6 = Ticket.create!(
@ -868,6 +874,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
@agent2.preferences['notification_config']['group_ids'] = [999] @agent2.preferences['notification_config']['group_ids'] = [999]
@agent2.save! @agent2.save!
travel 1.minute # to skip loopup cache in Transaction::Notification
# create ticket in group # create ticket in group
ApplicationHandleInfo.current = 'scheduler.postmaster' ApplicationHandleInfo.current = 'scheduler.postmaster'
ticket7 = Ticket.create!( ticket7 = Ticket.create!(