Performance: Don't check record associations if record is already present in assets structure.

This commit is contained in:
Thorsten Eckel 2019-11-18 20:19:35 +01:00 committed by Martin Edenhofer
parent cccec58c2e
commit 20c7cf9502
14 changed files with 204 additions and 191 deletions

View file

@ -29,18 +29,18 @@ returns
if !data[ app_model ]
data[ app_model ] = {}
end
if !data[ app_model ][ id ]
local_attributes = attributes_with_association_ids
return data if data[ app_model ][ id ]
local_attributes['object'] = ObjectLookup.by_id(local_attributes['activity_stream_object_id'])
local_attributes['type'] = TypeLookup.by_id(local_attributes['activity_stream_type_id'])
local_attributes = attributes_with_association_ids
# set temp. current attributes to assets pool to prevent
# loops, will be updated with lookup attributes later
data[ app_model ][ id ] = local_attributes
local_attributes['object'] = ObjectLookup.by_id(local_attributes['activity_stream_object_id'])
local_attributes['type'] = TypeLookup.by_id(local_attributes['activity_stream_type_id'])
ApplicationModel.assets_of_object_list([local_attributes], data)
end
# set temp. current attributes to assets pool to prevent
# loops, will be updated with lookup attributes later
data[ app_model ][ id ] = local_attributes
ApplicationModel.assets_of_object_list([local_attributes], data)
return data if !self['created_by_id']

View file

@ -29,27 +29,27 @@ returns
if !data[ app_model ]
data[ app_model ] = {}
end
if !data[ app_model ][ id ]
attributes = attributes_with_association_ids
return data if data[ app_model ][ id ]
# remove passwords if use is no admin
access = false
if UserInfo.current_user_id
user = User.lookup(id: UserInfo.current_user_id)
if user.permissions?('admin.channel')
access = true
end
end
if !access
%w[inbound outbound].each do |key|
if attributes['options'] && attributes['options'][key] && attributes['options'][key]['options']
attributes['options'][key]['options'].delete('password')
end
end
end
attributes = attributes_with_association_ids
data[ self.class.to_app_model ][ id ] = attributes
# remove passwords if use is no admin
access = false
if UserInfo.current_user_id
user = User.lookup(id: UserInfo.current_user_id)
if user.permissions?('admin.channel')
access = true
end
end
if !access
%w[inbound outbound].each do |key|
if attributes['options'] && attributes['options'][key] && attributes['options'][key]['options']
attributes['options'][key]['options'].delete('password')
end
end
end
data[ self.class.to_app_model ][ id ] = attributes
return data if !self['created_by_id'] && !self['updated_by_id']

View file

@ -24,20 +24,20 @@ returns
def assets(data)
app_model_chat_session = Chat::Session.to_app_model
app_model_chat = Chat.to_app_model
app_model_user = User.to_app_model
data[ app_model_chat_session ] ||= {}
if !data[ app_model_chat_session ][ id ]
data[ app_model_chat_session ][ id ] = attributes_with_association_ids
data[ app_model_chat_session ][ id ]['messages'] = []
messages.each do |message|
data[ app_model_chat_session ][ id ]['messages'].push message.attributes
end
data[ app_model_chat_session ][ id ]['tags'] = tag_list
if !data[ app_model_chat_session ]
data[ app_model_chat_session ] = {}
end
return data if data[ app_model_chat_session ][ id ]
data[ app_model_chat_session ][ id ] = attributes_with_association_ids
data[ app_model_chat_session ][ id ]['messages'] = []
messages.each do |message|
data[ app_model_chat_session ][ id ]['messages'].push message.attributes
end
data[ app_model_chat_session ][ id ]['tags'] = tag_list
app_model_chat = Chat.to_app_model
if !data[ app_model_chat ] || !data[ app_model_chat ][ chat_id ]
chat = Chat.lookup(id: chat_id)
if chat
@ -45,6 +45,7 @@ returns
end
end
app_model_user = User.to_app_model
%w[created_by_id updated_by_id].each do |local_user_id|
next if !self[ local_user_id ]
next if data[ app_model_user ] && data[ app_model_user ][ self[ local_user_id ] ]

View file

@ -29,14 +29,15 @@ returns
if !data[ app_model ]
data[ app_model ] = {}
end
return data if data[ app_model ][ id ]
data[ app_model ][ id ] = attributes_with_association_ids
data = assets_of_selector('condition', data)
data = assets_of_selector('perform', data)
if !data[ User.to_app_model ]
data[ User.to_app_model ] = {}
end
if !data[ app_model ][ id ]
data[ app_model ][ id ] = attributes_with_association_ids
data = assets_of_selector('condition', data)
data = assets_of_selector('perform', data)
end
%w[created_by_id updated_by_id].each do |local_user_id|
next if !self[ local_user_id ]
next if data[ User.to_app_model ][ self[ local_user_id ] ]

View file

@ -29,18 +29,18 @@ returns
if !data[ app_model ]
data[ app_model ] = {}
end
if !data[ app_model ][ id ]
local_attributes = attributes_with_association_ids
return data if data[ app_model ][ id ]
local_attributes['object'] = ObjectLookup.by_id(local_attributes['object_lookup_id'])
local_attributes['type'] = TypeLookup.by_id(local_attributes['type_lookup_id'])
local_attributes = attributes_with_association_ids
# set temp. current attributes to assets pool to prevent
# loops, will be updated with lookup attributes later
data[ app_model ][ id ] = local_attributes
local_attributes['object'] = ObjectLookup.by_id(local_attributes['object_lookup_id'])
local_attributes['type'] = TypeLookup.by_id(local_attributes['type_lookup_id'])
ApplicationModel.assets_of_object_list([local_attributes], data)
end
# set temp. current attributes to assets pool to prevent
# loops, will be updated with lookup attributes later
data[ app_model ][ id ] = local_attributes
ApplicationModel.assets_of_object_list([local_attributes], data)
return data if !self['created_by_id'] && !self['updated_by_id']

View file

@ -25,39 +25,41 @@ returns
def assets(data)
app_model_organization = Organization.to_app_model
app_model_user = User.to_app_model
if !data[ app_model_organization ]
data[ app_model_organization ] = {}
end
return data if data[ app_model_organization ][ id ]
local_attributes = attributes_with_association_ids
# set temp. current attributes to assets pool to prevent
# loops, will be updated with lookup attributes later
data[ app_model_organization ][ id ] = local_attributes
app_model_user = User.to_app_model
if local_attributes['member_ids'].present?
# feature used for different purpose; do limit references
if local_attributes['member_ids'].count > 100
local_attributes['member_ids'] = local_attributes['member_ids'].sort[0, 100]
end
local_attributes['member_ids'].each do |local_user_id|
next if data[ app_model_user ] && data[ app_model_user ][ local_user_id ]
user = User.lookup(id: local_user_id)
next if !user
data = user.assets(data)
end
end
data[ app_model_organization ][ id ] = local_attributes
if !data[ app_model_user ]
data[ app_model_user ] = {}
end
if !data[ app_model_organization ][ id ]
local_attributes = attributes_with_association_ids
# set temp. current attributes to assets pool to prevent
# loops, will be updated with lookup attributes later
data[ app_model_organization ][ id ] = local_attributes
if local_attributes['member_ids'].present?
# feature used for different purpose; do limit references
if local_attributes['member_ids'].count > 100
local_attributes['member_ids'] = local_attributes['member_ids'].sort[0, 100]
end
local_attributes['member_ids'].each do |local_user_id|
next if data[ app_model_user ] && data[ app_model_user ][ local_user_id ]
user = User.lookup(id: local_user_id)
next if !user
data = user.assets(data)
end
end
data[ app_model_organization ][ id ] = local_attributes
end
%w[created_by_id updated_by_id].each do |local_user_id|
next if !self[ local_user_id ]
next if data[ app_model_user ][ self[ local_user_id ] ]

View file

@ -25,26 +25,28 @@ returns
def assets(data)
app_model_overview = Overview.to_app_model
app_model_user = User.to_app_model
if !data[ app_model_overview ]
data[ app_model_overview ] = {}
end
return data if data[ app_model_overview ][ id ]
app_model_user = User.to_app_model
if !data[ app_model_user ]
data[ app_model_user ] = {}
end
if !data[ app_model_overview ][ id ]
data[ app_model_overview ][ id ] = attributes_with_association_ids
user_ids&.each do |local_user_id|
next if data[ app_model_user ][ local_user_id ]
user = User.lookup(id: local_user_id)
next if !user
data[ app_model_overview ][ id ] = attributes_with_association_ids
user_ids&.each do |local_user_id|
next if data[ app_model_user ][ local_user_id ]
data = user.assets(data)
end
data = assets_of_selector('condition', data)
user = User.lookup(id: local_user_id)
next if !user
data = user.assets(data)
end
data = assets_of_selector('condition', data)
%w[created_by_id updated_by_id].each do |local_user_id|
next if !self[ local_user_id ]
next if data[ app_model_user ][ self[ local_user_id ] ]

View file

@ -29,17 +29,17 @@ returns
if !data[ app_model ]
data[ app_model ] = {}
end
if !data[ app_model ][ id ]
local_attributes = attributes_with_association_ids
return data if data[ app_model ][ id ]
local_attributes['object'] = ObjectLookup.by_id(local_attributes['recent_view_object_id'])
local_attributes = attributes_with_association_ids
# set temp. current attributes to assets pool to prevent
# loops, will be updated with lookup attributes later
data[ app_model ][ id ] = local_attributes
local_attributes['object'] = ObjectLookup.by_id(local_attributes['recent_view_object_id'])
ApplicationModel.assets_of_object_list([local_attributes], data)
end
# set temp. current attributes to assets pool to prevent
# loops, will be updated with lookup attributes later
data[ app_model ][ id ] = local_attributes
ApplicationModel.assets_of_object_list([local_attributes], data)
return data if !self['created_by_id']

View file

@ -29,21 +29,21 @@ returns
if !data[ app_model ]
data[ app_model ] = {}
end
if !data[ app_model ][ id ]
local_attributes = attributes_with_association_ids
return data if data[ app_model ][ id ]
# set temp. current attributes to assets pool to prevent
# loops, will be updated with lookup attributes later
data[ app_model ][ id ] = local_attributes
local_attributes = attributes_with_association_ids
local_attributes['group_ids'].each_key do |group_id|
next if data[:Group] && data[:Group][group_id]
# set temp. current attributes to assets pool to prevent
# loops, will be updated with lookup attributes later
data[ app_model ][ id ] = local_attributes
group = Group.lookup(id: group_id)
next if !group
local_attributes['group_ids'].each_key do |group_id|
next if data[:Group] && data[:Group][group_id]
data = group.assets(data)
end
group = Group.lookup(id: group_id)
next if !group
data = group.assets(data)
end
return data if !self['created_by_id'] && !self['updated_by_id']

View file

@ -25,24 +25,26 @@ returns
def assets (data)
app_model_sla = Sla.to_app_model
app_model_user = User.to_app_model
if !data[ app_model_sla ]
data[ app_model_sla ] = {}
end
return data if data[ app_model_sla ][ id ]
data[ app_model_sla ][ id ] = attributes_with_association_ids
data = assets_of_selector('condition', data)
if calendar_id
calendar = Calendar.lookup(id: calendar_id)
if calendar
data = calendar.assets(data)
end
end
app_model_user = User.to_app_model
if !data[ app_model_user ]
data[ app_model_user ] = {}
end
if !data[ app_model_sla ][ id ]
data[ app_model_sla ][ id ] = attributes_with_association_ids
data = assets_of_selector('condition', data)
if calendar_id
calendar = Calendar.lookup(id: calendar_id)
if calendar
data = calendar.assets(data)
end
end
end
%w[created_by_id updated_by_id].each do |local_user_id|
next if !self[ local_user_id ]
next if data[ app_model_user ][ self[ local_user_id ] ]

View file

@ -24,8 +24,14 @@ returns
def assets(data)
app_model_ticket = Ticket.to_app_model
app_model_article = Ticket::Article.to_app_model
if !data[ app_model_article ]
data[ app_model_article ] = {}
end
return data if data[ app_model_article ][ id ]
app_model_ticket = Ticket.to_app_model
app_model_user = User.to_app_model
if !data[ app_model_ticket ]
@ -38,12 +44,7 @@ returns
end
end
if !data[ app_model_article ]
data[ app_model_article ] = {}
end
if !data[ app_model_article ][ id ]
data[ app_model_article ][ id ] = attributes_with_association_ids
end
data[ app_model_article ][ id ] = attributes_with_association_ids
%w[created_by_id updated_by_id origin_by_id].each do |local_user_id|
next if !self[ local_user_id ]

View file

@ -24,14 +24,16 @@ returns
def assets(data)
app_model_ticket = Ticket.to_app_model
app_model_user = User.to_app_model
if !data[ app_model_ticket ]
data[ app_model_ticket ] = {}
end
if !data[ app_model_ticket ][ id ]
data[ app_model_ticket ][ id ] = attributes_with_association_ids
end
return data if data[ app_model_ticket ][ id ]
data[ app_model_ticket ][ id ] = attributes_with_association_ids
app_model_user = User.to_app_model
%w[created_by_id updated_by_id owner_id customer_id].each do |local_user_id|
next if !self[ local_user_id ]
next if data[ app_model_user ] && data[ app_model_user ][ self[ local_user_id ] ]

View file

@ -24,20 +24,22 @@ returns
def assets(data)
app_model_overview = Trigger.to_app_model
app_model_user = User.to_app_model
app_model_trigger = Trigger.to_app_model
if !data[ app_model_overview ]
data[ app_model_overview ] = {}
if !data[ app_model_trigger ]
data[ app_model_trigger ] = {}
end
return data if data[ app_model_trigger ][ id ]
data[ app_model_trigger ][ id ] = attributes_with_association_ids
data = assets_of_selector('condition', data)
data = assets_of_selector('perform', data)
app_model_user = User.to_app_model
if !data[ app_model_user ]
data[ app_model_user ] = {}
end
if !data[ app_model_overview ][ id ]
data[ app_model_overview ][ id ] = attributes_with_association_ids
data = assets_of_selector('condition', data)
data = assets_of_selector('perform', data)
end
%w[created_by_id updated_by_id].each do |local_user_id|
next if !self[ local_user_id ]
next if data[ app_model_user ][ self[ local_user_id ] ]

View file

@ -30,65 +30,65 @@ returns
if !data[ app_model ]
data[ app_model ] = {}
end
if !data[ app_model ][ id ]
local_attributes = attributes_with_association_ids
return data if data[ app_model ][ id ]
# do not transfer crypted pw
local_attributes.delete('password')
local_attributes = attributes_with_association_ids
# set temp. current attributes to assets pool to prevent
# loops, will be updated with lookup attributes later
data[ app_model ][ id ] = local_attributes
# do not transfer crypted pw
local_attributes.delete('password')
# get linked accounts
local_attributes['accounts'] = {}
key = "User::authorizations::#{id}"
local_accounts = Cache.get(key)
if !local_accounts
local_accounts = {}
authorizations = self.authorizations()
authorizations.each do |authorization|
local_accounts[authorization.provider] = {
uid: authorization[:uid],
username: authorization[:username]
}
end
Cache.write(key, local_accounts)
# set temp. current attributes to assets pool to prevent
# loops, will be updated with lookup attributes later
data[ app_model ][ id ] = local_attributes
# get linked accounts
local_attributes['accounts'] = {}
key = "User::authorizations::#{id}"
local_accounts = Cache.get(key)
if !local_accounts
local_accounts = {}
authorizations = self.authorizations()
authorizations.each do |authorization|
local_accounts[authorization.provider] = {
uid: authorization[:uid],
username: authorization[:username]
}
end
local_attributes['accounts'] = local_accounts
# get roles
local_attributes['role_ids']&.each do |role_id|
next if data[:Role] && data[:Role][role_id]
role = Role.lookup(id: role_id)
next if !role
data = role.assets(data)
end
# get groups
local_attributes['group_ids']&.each do |group_id, _access|
next if data[:Group] && data[:Group][group_id]
group = Group.lookup(id: group_id)
next if !group
data = group.assets(data)
end
# get organizations
local_attributes['organization_ids']&.each do |organization_id|
next if data[:Organization] && data[:Organization][organization_id]
organization = Organization.lookup(id: organization_id)
next if !organization
data = organization.assets(data)
end
data[ app_model ][ id ] = local_attributes
Cache.write(key, local_accounts)
end
local_attributes['accounts'] = local_accounts
# get roles
local_attributes['role_ids']&.each do |role_id|
next if data[:Role] && data[:Role][role_id]
role = Role.lookup(id: role_id)
next if !role
data = role.assets(data)
end
# get groups
local_attributes['group_ids']&.each do |group_id, _access|
next if data[:Group] && data[:Group][group_id]
group = Group.lookup(id: group_id)
next if !group
data = group.assets(data)
end
# get organizations
local_attributes['organization_ids']&.each do |organization_id|
next if data[:Organization] && data[:Organization][organization_id]
organization = Organization.lookup(id: organization_id)
next if !organization
data = organization.assets(data)
end
data[ app_model ][ id ] = local_attributes
# add organization
if self.organization_id