##// 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 918 self._api_key = api_key
919 919
920 920 self.api_key = None
921 self.feed_token = ''
922 921 self.username = username
923 922 self.ip_addr = ip_addr
924 923 self.name = ''
@@ -1219,6 +1218,10 b' class AuthUser(object):'
1219 1218 def personal_repo_group(self):
1220 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 1225 @classmethod
1223 1226 def check_ip_allowed(cls, user_id, ip_addr, inherit_from_default):
1224 1227 allowed_ips = AuthUser.get_allowed_ips(
@@ -676,15 +676,19 b' class User(Base, BaseModel):'
676 676 .order_by(UserApiKeys.user_api_key_id.asc())\
677 677 .all()
678 678
679 @property
679 @LazyProperty
680 680 def feed_token(self):
681 681 return self.get_feed_token()
682 682
683 def get_feed_token(self):
683 def get_feed_token(self, cache=True):
684 684 feed_tokens = UserApiKeys.query()\
685 685 .filter(UserApiKeys.user == self)\
686 .filter(UserApiKeys.role == UserApiKeys.ROLE_FEED)\
687 .all()
686 .filter(UserApiKeys.role == UserApiKeys.ROLE_FEED)
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 692 if feed_tokens:
689 693 return feed_tokens[0].api_key
690 694 return 'NO_FEED_TOKEN_AVAILABLE'
@@ -697,8 +697,6 b' class UserModel(BaseModel):'
697 697 if k not in ['auth_tokens', 'permissions']:
698 698 setattr(auth_user, k, v)
699 699
700 # few extras
701 setattr(auth_user, 'feed_token', dbuser.feed_token)
702 700 except Exception:
703 701 log.error(traceback.format_exc())
704 702 auth_user.is_authenticated = False
General Comments 0
You need to be logged in to leave comments. Login now