##// END OF EJS Templates
feed-token, user, performance: lazy load the feed_token. We only need it for...
marcink -
r2424:76f7c7cb default
parent child Browse files
Show More
@@ -918,7 +918,6 b' class AuthUser(object):'
918 self._api_key = api_key
918 self._api_key = api_key
919
919
920 self.api_key = None
920 self.api_key = None
921 self.feed_token = ''
922 self.username = username
921 self.username = username
923 self.ip_addr = ip_addr
922 self.ip_addr = ip_addr
924 self.name = ''
923 self.name = ''
@@ -1219,6 +1218,10 b' class AuthUser(object):'
1219 def personal_repo_group(self):
1218 def personal_repo_group(self):
1220 return RepoGroup.get_user_personal_repo_group(self.user_id)
1219 return RepoGroup.get_user_personal_repo_group(self.user_id)
1221
1220
1221 @LazyProperty
1222 def feed_token(self):
1223 return self.get_instance().feed_token
1224
1222 @classmethod
1225 @classmethod
1223 def check_ip_allowed(cls, user_id, ip_addr, inherit_from_default):
1226 def check_ip_allowed(cls, user_id, ip_addr, inherit_from_default):
1224 allowed_ips = AuthUser.get_allowed_ips(
1227 allowed_ips = AuthUser.get_allowed_ips(
@@ -676,15 +676,19 b' class User(Base, BaseModel):'
676 .order_by(UserApiKeys.user_api_key_id.asc())\
676 .order_by(UserApiKeys.user_api_key_id.asc())\
677 .all()
677 .all()
678
678
679 @property
679 @LazyProperty
680 def feed_token(self):
680 def feed_token(self):
681 return self.get_feed_token()
681 return self.get_feed_token()
682
682
683 def get_feed_token(self):
683 def get_feed_token(self, cache=True):
684 feed_tokens = UserApiKeys.query()\
684 feed_tokens = UserApiKeys.query()\
685 .filter(UserApiKeys.user == self)\
685 .filter(UserApiKeys.user == self)\
686 .filter(UserApiKeys.role == UserApiKeys.ROLE_FEED)\
686 .filter(UserApiKeys.role == UserApiKeys.ROLE_FEED)
687 .all()
687 if cache:
688 feed_tokens = feed_tokens.options(
689 FromCache("long_term", "get_user_feed_token_%s" % self.user_id))
690
691 feed_tokens = feed_tokens.all()
688 if feed_tokens:
692 if feed_tokens:
689 return feed_tokens[0].api_key
693 return feed_tokens[0].api_key
690 return 'NO_FEED_TOKEN_AVAILABLE'
694 return 'NO_FEED_TOKEN_AVAILABLE'
@@ -697,8 +697,6 b' class UserModel(BaseModel):'
697 if k not in ['auth_tokens', 'permissions']:
697 if k not in ['auth_tokens', 'permissions']:
698 setattr(auth_user, k, v)
698 setattr(auth_user, k, v)
699
699
700 # few extras
701 setattr(auth_user, 'feed_token', dbuser.feed_token)
702 except Exception:
700 except Exception:
703 log.error(traceback.format_exc())
701 log.error(traceback.format_exc())
704 auth_user.is_authenticated = False
702 auth_user.is_authenticated = False
General Comments 0
You need to be logged in to leave comments. Login now