From e51b376b439f7f66f69f7504fcc900184d98f341 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 13 Aug 2014 13:32:43 +0200 Subject: [PATCH] Moved to Model.lookup() for asset generation to speed up. --- app/controllers/users_controller.rb | 2 +- app/models/application_model/assets.rb | 2 +- app/models/history/assets.rb | 2 +- app/models/organization/assets.rb | 4 ++-- app/models/ticket/article/assets.rb | 2 +- app/models/ticket/assets.rb | 4 ++-- app/models/user/assets.rb | 10 +++++----- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index d84b7bd2b..5cfaf1c1f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -70,7 +70,7 @@ curl http://localhost/api/v1/users.json -v -u #{login}:#{password} end users_all = [] users.each {|user| - users_all.push User.find( user.id ).attributes_with_associations + users_all.push User.lookup( :id => user.id ).attributes_with_associations } render :json => users_all, :status => :ok end diff --git a/app/models/application_model/assets.rb b/app/models/application_model/assets.rb index fd5ed664e..4fa7f1b1c 100644 --- a/app/models/application_model/assets.rb +++ b/app/models/application_model/assets.rb @@ -33,7 +33,7 @@ returns ['created_by_id', 'updated_by_id'].each {|item| if self[ item ] if !data[ User.to_app_model ] || !data[ User.to_app_model ][ self[ item ] ] - user = User.find( self[ item ] ) + user = User.lookup( :id => self[ item ] ) data = user.assets( data ) end end diff --git a/app/models/history/assets.rb b/app/models/history/assets.rb index 92071dcc7..8f37e1cf4 100644 --- a/app/models/history/assets.rb +++ b/app/models/history/assets.rb @@ -23,7 +23,7 @@ returns def assets (data) if !data[ User.to_app_model ] || !data[ User.to_app_model ][ self['created_by_id'] ] - user = User.find( self['created_by_id'] ) + user = User.lookup( :id => self['created_by_id'] ) data = user.assets( data ) end diff --git a/app/models/organization/assets.rb b/app/models/organization/assets.rb index b833f7c5f..9ad1eacee 100644 --- a/app/models/organization/assets.rb +++ b/app/models/organization/assets.rb @@ -33,7 +33,7 @@ returns if data[ Organization.to_app_model ][ self.id ]['member_ids'] data[ Organization.to_app_model ][ self.id ]['member_ids'].each {|user_id| if !data[ User.to_app_model ][ user_id ] - user = User.find( user_id ) + user = User.lookup( :id => user_id ) data = user.assets( data ) end } @@ -42,7 +42,7 @@ returns ['created_by_id', 'updated_by_id'].each {|item| if self[ item ] if !data[ User.to_app_model ][ self[ item ] ] - user = User.find( self[ item ] ) + user = User.lookup( :id => self[ item ] ) data = user.assets( data ) end end diff --git a/app/models/ticket/article/assets.rb b/app/models/ticket/article/assets.rb index abbf6ba60..42bb98024 100644 --- a/app/models/ticket/article/assets.rb +++ b/app/models/ticket/article/assets.rb @@ -44,7 +44,7 @@ returns ['created_by_id', 'updated_by_id'].each {|item| if self[ item ] if !data[ User.to_app_model ] || !data[ User.to_app_model ][ self[ item ] ] - user = User.find( self[ item ] ) + user = User.lookup( :id => self[ item ] ) data = user.assets( data ) end end diff --git a/app/models/ticket/assets.rb b/app/models/ticket/assets.rb index 4c6923e50..856ef52fd 100644 --- a/app/models/ticket/assets.rb +++ b/app/models/ticket/assets.rb @@ -27,12 +27,12 @@ returns data[ Ticket.to_app_model ] = {} end if !data[ Ticket.to_app_model ][ self.id ] - data[ Ticket.to_app_model ][ self.id ] = self.attributes + data[ Ticket.to_app_model ][ self.id ] = self.attributes_with_associations end ['created_by_id', 'updated_by_id', 'owner_id', 'customer_id'].each {|item| if self[ item ] if !data[ User.to_app_model ] || !data[ User.to_app_model ][ self[ item ] ] - user = User.find( self[ item ] ) + user = User.lookup( :id => self[ item ] ) data = user.assets( data ) end end diff --git a/app/models/user/assets.rb b/app/models/user/assets.rb index 10ca53a20..03e848747 100644 --- a/app/models/user/assets.rb +++ b/app/models/user/assets.rb @@ -46,7 +46,7 @@ returns # get roles if attributes['role_ids'] attributes['role_ids'].each {|role_id| - role = Role.find(role_id) + role = Role.lookup( :id => role_id ) data = role.assets( data ) } end @@ -54,7 +54,7 @@ returns # get groups if attributes['group_ids'] attributes['group_ids'].each {|group_id| - group = Group.find(group_id) + group = Group.lookup( :id => group_id ) data = group.assets( data ) } end @@ -62,21 +62,21 @@ returns # get groups if attributes['organization_ids'] attributes['organization_ids'].each {|organization_id| - organization = Organization.find(organization_id) + organization = Organization.lookup( :id => organization_id ) data = organization.assets( data ) } end end if self.organization_id if !data[ Organization.to_app_model ] || !data[ Organization.to_app_model ][ self.organization_id ] - organization = Organization.find( self.organization_id ) + organization = Organization.lookup( :id => self.organization_id ) data = organization.assets( data ) end end ['created_by_id', 'updated_by_id'].each {|item| if self[ item ] if !data[ User.to_app_model ][ self[ item ] ] - user = User.find( self[ item ] ) + user = User.lookup( :id => self[ item ] ) data = user.assets( data ) end end