Skip to content
Permalink
Browse files

Performance: When many tickets have reached the reminder or are escal…

…ated (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.
  • Loading branch information...
zammad-sync authored and thorsteneckel committed Oct 4, 2019
1 parent 4182b0b commit f57f0486a3ec3c0d32544658189ee77782e19178
Showing with 17 additions and 1 deletion.
  1. +9 −1 app/models/transaction/notification.rb
  2. +8 −0 test/unit/ticket_notification_test.rb
@@ -51,7 +51,7 @@ def perform
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 @@ def recursive_ooo_replacements(user:, replacements:, reasons:, level: 0)
)
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
@@ -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!(

0 comments on commit f57f048

Please sign in to comment.
You can’t perform that action at this time.