##// END OF EJS Templates
user: speed up data propagatation for auth users by pre-filling only selected variables...
marcink -
r4018:e79bd088 default
parent child Browse files
Show More
@@ -696,6 +696,17 b' class User(Base, BaseModel):'
696 696 .all()
697 697 return [self.email] + [x.email for x in other]
698 698
699 def emails_cached(self):
700 emails = UserEmailMap.query()\
701 .filter(UserEmailMap.user == self) \
702 .order_by(UserEmailMap.email_id.asc())
703
704 emails = emails.options(
705 FromCache("sql_cache_short", "get_user_{}_emails".format(self.user_id))
706 )
707
708 return [self.email] + [x.email for x in emails]
709
699 710 @property
700 711 def auth_tokens(self):
701 712 auth_tokens = self.get_auth_tokens()
@@ -854,6 +865,10 b' class User(Base, BaseModel):'
854 865 def is_admin(self):
855 866 return self.admin
856 867
868 @property
869 def language(self):
870 return self.user_data.get('language')
871
857 872 def AuthUser(self, **kwargs):
858 873 """
859 874 Returns instance of AuthUser for this user
@@ -734,19 +734,40 b' class UserModel(BaseModel):'
734 734 return False
735 735
736 736 log.debug('AuthUser: filling found user:%s data', dbuser)
737 user_data = dbuser.get_dict()
738 737
739 user_data.update({
740 # set explicit the safe escaped values
738 attrs = {
739 'user_id': dbuser.user_id,
740 'username': dbuser.username,
741 'name': dbuser.name,
741 742 'first_name': dbuser.first_name,
743 'firstname': dbuser.firstname,
742 744 'last_name': dbuser.last_name,
743 })
745 'lastname': dbuser.lastname,
746 'admin': dbuser.admin,
747 'active': dbuser.active,
748
749 'email': dbuser.email,
750 'emails': dbuser.emails_cached(),
751 'short_contact': dbuser.short_contact,
752 'full_contact': dbuser.full_contact,
753 'full_name': dbuser.full_name,
754 'full_name_or_username': dbuser.full_name_or_username,
744 755
745 for k, v in user_data.items():
746 # properties of auth user we dont update
747 if k not in ['auth_tokens', 'permissions']:
748 setattr(auth_user, k, v)
756 '_api_key': dbuser._api_key,
757 '_user_data': dbuser._user_data,
758
759 'created_on': dbuser.created_on,
760 'extern_name': dbuser.extern_name,
761 'extern_type': dbuser.extern_type,
749 762
763 'inherit_default_permissions': dbuser.inherit_default_permissions,
764
765 'language': dbuser.language,
766 'last_activity': dbuser.last_activity,
767 'last_login': dbuser.last_login,
768 'password': dbuser.password,
769 }
770 auth_user.__dict__.update(attrs)
750 771 except Exception:
751 772 log.error(traceback.format_exc())
752 773 auth_user.is_authenticated = False
General Comments 0
You need to be logged in to leave comments. Login now