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 ] if !data[ app_model ]
data[ app_model ] = {} data[ app_model ] = {}
end end
if !data[ app_model ][ id ] return data if data[ app_model ][ id ]
local_attributes = attributes_with_association_ids
local_attributes['object'] = ObjectLookup.by_id(local_attributes['activity_stream_object_id']) local_attributes = attributes_with_association_ids
local_attributes['type'] = TypeLookup.by_id(local_attributes['activity_stream_type_id'])
# set temp. current attributes to assets pool to prevent local_attributes['object'] = ObjectLookup.by_id(local_attributes['activity_stream_object_id'])
# loops, will be updated with lookup attributes later local_attributes['type'] = TypeLookup.by_id(local_attributes['activity_stream_type_id'])
data[ app_model ][ id ] = local_attributes
ApplicationModel.assets_of_object_list([local_attributes], data) # set temp. current attributes to assets pool to prevent
end # 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'] return data if !self['created_by_id']

View file

@ -29,27 +29,27 @@ returns
if !data[ app_model ] if !data[ app_model ]
data[ app_model ] = {} data[ app_model ] = {}
end end
if !data[ app_model ][ id ] return data if data[ app_model ][ id ]
attributes = attributes_with_association_ids
# remove passwords if use is no admin attributes = attributes_with_association_ids
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 # 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 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'] return data if !self['created_by_id'] && !self['updated_by_id']

View file

@ -24,20 +24,20 @@ returns
def assets(data) def assets(data)
app_model_chat_session = Chat::Session.to_app_model 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 ]
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
end 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 ] if !data[ app_model_chat ] || !data[ app_model_chat ][ chat_id ]
chat = Chat.lookup(id: chat_id) chat = Chat.lookup(id: chat_id)
if chat if chat
@ -45,6 +45,7 @@ returns
end end
end end
app_model_user = User.to_app_model
%w[created_by_id updated_by_id].each do |local_user_id| %w[created_by_id updated_by_id].each do |local_user_id|
next if !self[ local_user_id ] next if !self[ local_user_id ]
next if data[ app_model_user ] && data[ app_model_user ][ 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 ] if !data[ app_model ]
data[ app_model ] = {} data[ app_model ] = {}
end 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 ] if !data[ User.to_app_model ]
data[ User.to_app_model ] = {} data[ User.to_app_model ] = {}
end 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| %w[created_by_id updated_by_id].each do |local_user_id|
next if !self[ local_user_id ] next if !self[ local_user_id ]
next if data[ User.to_app_model ][ 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 ] if !data[ app_model ]
data[ app_model ] = {} data[ app_model ] = {}
end end
if !data[ app_model ][ id ] return data if data[ app_model ][ id ]
local_attributes = attributes_with_association_ids
local_attributes['object'] = ObjectLookup.by_id(local_attributes['object_lookup_id']) local_attributes = attributes_with_association_ids
local_attributes['type'] = TypeLookup.by_id(local_attributes['type_lookup_id'])
# set temp. current attributes to assets pool to prevent local_attributes['object'] = ObjectLookup.by_id(local_attributes['object_lookup_id'])
# loops, will be updated with lookup attributes later local_attributes['type'] = TypeLookup.by_id(local_attributes['type_lookup_id'])
data[ app_model ][ id ] = local_attributes
ApplicationModel.assets_of_object_list([local_attributes], data) # set temp. current attributes to assets pool to prevent
end # 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'] return data if !self['created_by_id'] && !self['updated_by_id']

View file

@ -25,39 +25,41 @@ returns
def assets(data) def assets(data)
app_model_organization = Organization.to_app_model app_model_organization = Organization.to_app_model
app_model_user = User.to_app_model
if !data[ app_model_organization ] if !data[ app_model_organization ]
data[ app_model_organization ] = {} data[ app_model_organization ] = {}
end 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 ] if !data[ app_model_user ]
data[ app_model_user ] = {} data[ app_model_user ] = {}
end 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| %w[created_by_id updated_by_id].each do |local_user_id|
next if !self[ local_user_id ] next if !self[ local_user_id ]
next if data[ app_model_user ][ self[ local_user_id ] ] next if data[ app_model_user ][ self[ local_user_id ] ]

View file

@ -25,26 +25,28 @@ returns
def assets(data) def assets(data)
app_model_overview = Overview.to_app_model app_model_overview = Overview.to_app_model
app_model_user = User.to_app_model
if !data[ app_model_overview ] if !data[ app_model_overview ]
data[ app_model_overview ] = {} data[ app_model_overview ] = {}
end end
return data if data[ app_model_overview ][ id ]
app_model_user = User.to_app_model
if !data[ app_model_user ] if !data[ app_model_user ]
data[ app_model_user ] = {} data[ app_model_user ] = {}
end 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) data[ app_model_overview ][ id ] = attributes_with_association_ids
next if !user user_ids&.each do |local_user_id|
next if data[ app_model_user ][ local_user_id ]
data = user.assets(data) user = User.lookup(id: local_user_id)
end next if !user
data = assets_of_selector('condition', data)
data = user.assets(data)
end end
data = assets_of_selector('condition', data)
%w[created_by_id updated_by_id].each do |local_user_id| %w[created_by_id updated_by_id].each do |local_user_id|
next if !self[ local_user_id ] next if !self[ local_user_id ]
next if data[ app_model_user ][ 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 ] if !data[ app_model ]
data[ app_model ] = {} data[ app_model ] = {}
end end
if !data[ app_model ][ id ] return data if data[ app_model ][ id ]
local_attributes = attributes_with_association_ids
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 local_attributes['object'] = ObjectLookup.by_id(local_attributes['recent_view_object_id'])
# loops, will be updated with lookup attributes later
data[ app_model ][ id ] = local_attributes
ApplicationModel.assets_of_object_list([local_attributes], data) # set temp. current attributes to assets pool to prevent
end # 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'] return data if !self['created_by_id']

View file

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

View file

@ -25,24 +25,26 @@ returns
def assets (data) def assets (data)
app_model_sla = Sla.to_app_model app_model_sla = Sla.to_app_model
app_model_user = User.to_app_model
if !data[ app_model_sla ] if !data[ app_model_sla ]
data[ app_model_sla ] = {} data[ app_model_sla ] = {}
end 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 ] if !data[ app_model_user ]
data[ app_model_user ] = {} data[ app_model_user ] = {}
end 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| %w[created_by_id updated_by_id].each do |local_user_id|
next if !self[ local_user_id ] next if !self[ local_user_id ]
next if data[ app_model_user ][ self[ local_user_id ] ] next if data[ app_model_user ][ self[ local_user_id ] ]

View file

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

View file

@ -24,14 +24,16 @@ returns
def assets(data) def assets(data)
app_model_ticket = Ticket.to_app_model app_model_ticket = Ticket.to_app_model
app_model_user = User.to_app_model
if !data[ app_model_ticket ] if !data[ app_model_ticket ]
data[ app_model_ticket ] = {} data[ app_model_ticket ] = {}
end end
if !data[ app_model_ticket ][ id ] return data if data[ app_model_ticket ][ id ]
data[ app_model_ticket ][ id ] = attributes_with_association_ids
end 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| %w[created_by_id updated_by_id owner_id customer_id].each do |local_user_id|
next if !self[ local_user_id ] next if !self[ local_user_id ]
next if data[ app_model_user ] && data[ app_model_user ][ 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) def assets(data)
app_model_overview = Trigger.to_app_model app_model_trigger = Trigger.to_app_model
app_model_user = User.to_app_model
if !data[ app_model_overview ] if !data[ app_model_trigger ]
data[ app_model_overview ] = {} data[ app_model_trigger ] = {}
end 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 ] if !data[ app_model_user ]
data[ app_model_user ] = {} data[ app_model_user ] = {}
end 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| %w[created_by_id updated_by_id].each do |local_user_id|
next if !self[ local_user_id ] next if !self[ local_user_id ]
next if data[ app_model_user ][ 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 ] if !data[ app_model ]
data[ app_model ] = {} data[ app_model ] = {}
end end
if !data[ app_model ][ id ] return data if data[ app_model ][ id ]
local_attributes = attributes_with_association_ids
# do not transfer crypted pw local_attributes = attributes_with_association_ids
local_attributes.delete('password')
# set temp. current attributes to assets pool to prevent # do not transfer crypted pw
# loops, will be updated with lookup attributes later local_attributes.delete('password')
data[ app_model ][ id ] = local_attributes
# get linked accounts # set temp. current attributes to assets pool to prevent
local_attributes['accounts'] = {} # loops, will be updated with lookup attributes later
key = "User::authorizations::#{id}" data[ app_model ][ id ] = local_attributes
local_accounts = Cache.get(key)
if !local_accounts # get linked accounts
local_accounts = {} local_attributes['accounts'] = {}
authorizations = self.authorizations() key = "User::authorizations::#{id}"
authorizations.each do |authorization| local_accounts = Cache.get(key)
local_accounts[authorization.provider] = { if !local_accounts
uid: authorization[:uid], local_accounts = {}
username: authorization[:username] authorizations = self.authorizations()
} authorizations.each do |authorization|
end local_accounts[authorization.provider] = {
Cache.write(key, local_accounts) uid: authorization[:uid],
username: authorization[:username]
}
end end
local_attributes['accounts'] = local_accounts Cache.write(key, 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
end 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 # add organization
if self.organization_id if self.organization_id