Moved to Model.lookup() for asset generation to speed up.

This commit is contained in:
Martin Edenhofer 2014-08-13 13:32:43 +02:00
parent 47e89388bf
commit e51b376b43
7 changed files with 13 additions and 13 deletions

View file

@ -70,7 +70,7 @@ curl http://localhost/api/v1/users.json -v -u #{login}:#{password}
end end
users_all = [] users_all = []
users.each {|user| 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 render :json => users_all, :status => :ok
end end

View file

@ -33,7 +33,7 @@ returns
['created_by_id', 'updated_by_id'].each {|item| ['created_by_id', 'updated_by_id'].each {|item|
if self[ item ] if self[ item ]
if !data[ User.to_app_model ] || !data[ User.to_app_model ][ 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 ) data = user.assets( data )
end end
end end

View file

@ -23,7 +23,7 @@ returns
def assets (data) def assets (data)
if !data[ User.to_app_model ] || !data[ User.to_app_model ][ self['created_by_id'] ] 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 ) data = user.assets( data )
end end

View file

@ -33,7 +33,7 @@ returns
if data[ Organization.to_app_model ][ self.id ]['member_ids'] if data[ Organization.to_app_model ][ self.id ]['member_ids']
data[ Organization.to_app_model ][ self.id ]['member_ids'].each {|user_id| data[ Organization.to_app_model ][ self.id ]['member_ids'].each {|user_id|
if !data[ User.to_app_model ][ 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 ) data = user.assets( data )
end end
} }
@ -42,7 +42,7 @@ returns
['created_by_id', 'updated_by_id'].each {|item| ['created_by_id', 'updated_by_id'].each {|item|
if self[ item ] if self[ item ]
if !data[ User.to_app_model ][ 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 ) data = user.assets( data )
end end
end end

View file

@ -44,7 +44,7 @@ returns
['created_by_id', 'updated_by_id'].each {|item| ['created_by_id', 'updated_by_id'].each {|item|
if self[ item ] if self[ item ]
if !data[ User.to_app_model ] || !data[ User.to_app_model ][ 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 ) data = user.assets( data )
end end
end end

View file

@ -27,12 +27,12 @@ returns
data[ Ticket.to_app_model ] = {} data[ Ticket.to_app_model ] = {}
end end
if !data[ Ticket.to_app_model ][ self.id ] 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 end
['created_by_id', 'updated_by_id', 'owner_id', 'customer_id'].each {|item| ['created_by_id', 'updated_by_id', 'owner_id', 'customer_id'].each {|item|
if self[ item ] if self[ item ]
if !data[ User.to_app_model ] || !data[ User.to_app_model ][ 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 ) data = user.assets( data )
end end
end end

View file

@ -46,7 +46,7 @@ returns
# get roles # get roles
if attributes['role_ids'] if attributes['role_ids']
attributes['role_ids'].each {|role_id| attributes['role_ids'].each {|role_id|
role = Role.find(role_id) role = Role.lookup( :id => role_id )
data = role.assets( data ) data = role.assets( data )
} }
end end
@ -54,7 +54,7 @@ returns
# get groups # get groups
if attributes['group_ids'] if attributes['group_ids']
attributes['group_ids'].each {|group_id| attributes['group_ids'].each {|group_id|
group = Group.find(group_id) group = Group.lookup( :id => group_id )
data = group.assets( data ) data = group.assets( data )
} }
end end
@ -62,21 +62,21 @@ returns
# get groups # get groups
if attributes['organization_ids'] if attributes['organization_ids']
attributes['organization_ids'].each {|organization_id| attributes['organization_ids'].each {|organization_id|
organization = Organization.find(organization_id) organization = Organization.lookup( :id => organization_id )
data = organization.assets( data ) data = organization.assets( data )
} }
end end
end end
if self.organization_id if self.organization_id
if !data[ Organization.to_app_model ] || !data[ Organization.to_app_model ][ 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 ) data = organization.assets( data )
end end
end end
['created_by_id', 'updated_by_id'].each {|item| ['created_by_id', 'updated_by_id'].each {|item|
if self[ item ] if self[ item ]
if !data[ User.to_app_model ][ 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 ) data = user.assets( data )
end end
end end