Improved caching if find_fulldata() and reduced data.
This commit is contained in:
parent
7b3d341568
commit
f76af2d2b6
1 changed files with 32 additions and 9 deletions
|
@ -58,30 +58,53 @@ class User < ActiveRecord::Base
|
||||||
|
|
||||||
# get user
|
# get user
|
||||||
user = User.find(user_id)
|
user = User.find(user_id)
|
||||||
|
data = user.attributes
|
||||||
|
|
||||||
|
|
||||||
# get linked accounts
|
# get linked accounts
|
||||||
user['accounts'] = {}
|
data['accounts'] = {}
|
||||||
authorizations = user.authorizations() || []
|
authorizations = user.authorizations() || []
|
||||||
authorizations.each do | authorization |
|
authorizations.each do | authorization |
|
||||||
user['accounts'][authorization.provider] = {
|
data['accounts'][authorization.provider] = {
|
||||||
:uid => authorization[:uid],
|
:uid => authorization[:uid],
|
||||||
:username => authorization[:username]
|
:username => authorization[:username]
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
# set roles
|
# set roles
|
||||||
user['roles'] = user.roles.select('id, name').where(:active => true)
|
roles = []
|
||||||
user['groups'] = user.groups.select('id, name').where(:active => true)
|
user.roles.select('id, name').where( :active => true ).each { |role|
|
||||||
user['organization'] = user.organization
|
roles.push role
|
||||||
user['organizations'] = user.organizations.select('id, name').where(:active => true)
|
}
|
||||||
|
data['roles'] = roles
|
||||||
|
|
||||||
@@cache[user_id] = user
|
groups = []
|
||||||
|
user.groups.select('id, name').where( :active => true ).each { |group|
|
||||||
|
groups.push group
|
||||||
|
}
|
||||||
|
data['groups'] = groups
|
||||||
|
|
||||||
return user
|
organization = user.organization
|
||||||
|
data['organization'] = organization
|
||||||
|
|
||||||
|
organizations = []
|
||||||
|
user.organizations.select('id, name').where( :active => true ).each { |organization|
|
||||||
|
organizations.push organization
|
||||||
|
}
|
||||||
|
data['organizations'] = organizations
|
||||||
|
|
||||||
|
@@cache[user_id] = data
|
||||||
|
|
||||||
|
return data
|
||||||
|
end
|
||||||
|
|
||||||
|
def cache_reset
|
||||||
|
@@cache[self.id] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def delete_cache
|
def delete_cache
|
||||||
|
puts 'delete_cache', self.insepct
|
||||||
@@cache[self.id] = nil
|
@@cache[self.id] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue