Performance: User preference store YAML parsing for notification settings is slow.
This commit is contained in:
parent
b468134e93
commit
f9a26d7254
2 changed files with 22 additions and 4 deletions
|
@ -30,10 +30,20 @@ returns
|
||||||
type = map[type]
|
type = map[type]
|
||||||
end
|
end
|
||||||
|
|
||||||
return if !user.preferences
|
# this cache will optimize the preference catch performance
|
||||||
return if !user.preferences['notification_config']
|
# because of the yaml deserialization its pretty slow
|
||||||
|
# on many tickets you we cache it.
|
||||||
|
user_preferences = Cache.get("NotificationFactory::Mailer.notification_settings::#{user.id}")
|
||||||
|
if user_preferences.blank?
|
||||||
|
user_preferences = user.preferences
|
||||||
|
|
||||||
matrix = user.preferences['notification_config']['matrix']
|
Cache.write("NotificationFactory::Mailer.notification_settings::#{user.id}", user_preferences, expires_in: 20.seconds)
|
||||||
|
end
|
||||||
|
|
||||||
|
return if !user_preferences
|
||||||
|
return if !user_preferences['notification_config']
|
||||||
|
|
||||||
|
matrix = user_preferences['notification_config']['matrix']
|
||||||
return if !matrix
|
return if !matrix
|
||||||
|
|
||||||
owned_by_nobody = false
|
owned_by_nobody = false
|
||||||
|
@ -60,7 +70,7 @@ returns
|
||||||
|
|
||||||
# check if group is in selected groups
|
# check if group is in selected groups
|
||||||
if !owned_by_me
|
if !owned_by_me
|
||||||
selected_group_ids = user.preferences['notification_config']['group_ids']
|
selected_group_ids = user_preferences['notification_config']['group_ids']
|
||||||
if selected_group_ids.is_a?(Array)
|
if selected_group_ids.is_a?(Array)
|
||||||
hit = nil
|
hit = nil
|
||||||
if selected_group_ids.blank?
|
if selected_group_ids.blank?
|
||||||
|
|
|
@ -161,6 +161,7 @@ class NotificationFactoryMailerTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
agent1.preferences[:notification_config][:group_ids] = nil
|
agent1.preferences[:notification_config][:group_ids] = nil
|
||||||
agent1.save
|
agent1.save
|
||||||
|
travel 30.seconds
|
||||||
|
|
||||||
result = NotificationFactory::Mailer.notification_settings(agent1, ticket1, 'create')
|
result = NotificationFactory::Mailer.notification_settings(agent1, ticket1, 'create')
|
||||||
assert_equal(true, result[:channels][:online])
|
assert_equal(true, result[:channels][:online])
|
||||||
|
@ -180,6 +181,7 @@ class NotificationFactoryMailerTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
agent2.preferences[:notification_config][:group_ids] = nil
|
agent2.preferences[:notification_config][:group_ids] = nil
|
||||||
agent2.save
|
agent2.save
|
||||||
|
travel 30.seconds
|
||||||
|
|
||||||
result = NotificationFactory::Mailer.notification_settings(agent2, ticket1, 'create')
|
result = NotificationFactory::Mailer.notification_settings(agent2, ticket1, 'create')
|
||||||
assert_equal(true, result[:channels][:online])
|
assert_equal(true, result[:channels][:online])
|
||||||
|
@ -198,6 +200,7 @@ class NotificationFactoryMailerTest < ActiveSupport::TestCase
|
||||||
# no group selection
|
# no group selection
|
||||||
agent1.preferences[:notification_config][:group_ids] = []
|
agent1.preferences[:notification_config][:group_ids] = []
|
||||||
agent1.save
|
agent1.save
|
||||||
|
travel 30.seconds
|
||||||
|
|
||||||
result = NotificationFactory::Mailer.notification_settings(agent1, ticket1, 'create')
|
result = NotificationFactory::Mailer.notification_settings(agent1, ticket1, 'create')
|
||||||
assert_equal(true, result[:channels][:online])
|
assert_equal(true, result[:channels][:online])
|
||||||
|
@ -217,6 +220,7 @@ class NotificationFactoryMailerTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
agent2.preferences[:notification_config][:group_ids] = []
|
agent2.preferences[:notification_config][:group_ids] = []
|
||||||
agent2.save
|
agent2.save
|
||||||
|
travel 30.seconds
|
||||||
|
|
||||||
result = NotificationFactory::Mailer.notification_settings(agent2, ticket1, 'create')
|
result = NotificationFactory::Mailer.notification_settings(agent2, ticket1, 'create')
|
||||||
assert_equal(true, result[:channels][:online])
|
assert_equal(true, result[:channels][:online])
|
||||||
|
@ -234,6 +238,7 @@ class NotificationFactoryMailerTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
agent1.preferences[:notification_config][:group_ids] = ['-']
|
agent1.preferences[:notification_config][:group_ids] = ['-']
|
||||||
agent1.save
|
agent1.save
|
||||||
|
travel 30.seconds
|
||||||
|
|
||||||
result = NotificationFactory::Mailer.notification_settings(agent1, ticket1, 'create')
|
result = NotificationFactory::Mailer.notification_settings(agent1, ticket1, 'create')
|
||||||
assert_equal(true, result[:channels][:online])
|
assert_equal(true, result[:channels][:online])
|
||||||
|
@ -253,6 +258,7 @@ class NotificationFactoryMailerTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
agent2.preferences[:notification_config][:group_ids] = ['-']
|
agent2.preferences[:notification_config][:group_ids] = ['-']
|
||||||
agent2.save
|
agent2.save
|
||||||
|
travel 30.seconds
|
||||||
|
|
||||||
result = NotificationFactory::Mailer.notification_settings(agent2, ticket1, 'create')
|
result = NotificationFactory::Mailer.notification_settings(agent2, ticket1, 'create')
|
||||||
assert_equal(true, result[:channels][:online])
|
assert_equal(true, result[:channels][:online])
|
||||||
|
@ -271,6 +277,7 @@ class NotificationFactoryMailerTest < ActiveSupport::TestCase
|
||||||
# dedecated group selection
|
# dedecated group selection
|
||||||
agent1.preferences[:notification_config][:group_ids] = [Group.lookup(name: 'Users').id]
|
agent1.preferences[:notification_config][:group_ids] = [Group.lookup(name: 'Users').id]
|
||||||
agent1.save
|
agent1.save
|
||||||
|
travel 30.seconds
|
||||||
|
|
||||||
result = NotificationFactory::Mailer.notification_settings(agent1, ticket1, 'create')
|
result = NotificationFactory::Mailer.notification_settings(agent1, ticket1, 'create')
|
||||||
assert_equal(true, result[:channels][:online])
|
assert_equal(true, result[:channels][:online])
|
||||||
|
@ -289,6 +296,7 @@ class NotificationFactoryMailerTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
agent2.preferences[:notification_config][:group_ids] = [Group.lookup(name: 'Users').id]
|
agent2.preferences[:notification_config][:group_ids] = [Group.lookup(name: 'Users').id]
|
||||||
agent2.save
|
agent2.save
|
||||||
|
travel 30.seconds
|
||||||
|
|
||||||
result = NotificationFactory::Mailer.notification_settings(agent2, ticket1, 'create')
|
result = NotificationFactory::Mailer.notification_settings(agent2, ticket1, 'create')
|
||||||
assert_equal(true, result[:channels][:online])
|
assert_equal(true, result[:channels][:online])
|
||||||
|
|
Loading…
Reference in a new issue