# HG changeset patch # User Marcin Kuzminski # Date 2017-12-04 11:14:01 # Node ID 76f7c7cb15c74893e9c18abdf4bbba3551f3b88f # Parent ce5d852c73cc9a9c4295f71d200f29ff132498a1 feed-token, user, performance: lazy load the feed_token. We only need it for scope of web requests. For vcs operations, we don't need it. - 20ms to load this can save up much time for SVN requests. diff --git a/rhodecode/lib/auth.py b/rhodecode/lib/auth.py --- a/rhodecode/lib/auth.py +++ b/rhodecode/lib/auth.py @@ -918,7 +918,6 @@ class AuthUser(object): self._api_key = api_key self.api_key = None - self.feed_token = '' self.username = username self.ip_addr = ip_addr self.name = '' @@ -1219,6 +1218,10 @@ class AuthUser(object): def personal_repo_group(self): return RepoGroup.get_user_personal_repo_group(self.user_id) + @LazyProperty + def feed_token(self): + return self.get_instance().feed_token + @classmethod def check_ip_allowed(cls, user_id, ip_addr, inherit_from_default): allowed_ips = AuthUser.get_allowed_ips( diff --git a/rhodecode/model/db.py b/rhodecode/model/db.py --- a/rhodecode/model/db.py +++ b/rhodecode/model/db.py @@ -676,15 +676,19 @@ class User(Base, BaseModel): .order_by(UserApiKeys.user_api_key_id.asc())\ .all() - @property + @LazyProperty def feed_token(self): return self.get_feed_token() - def get_feed_token(self): + def get_feed_token(self, cache=True): feed_tokens = UserApiKeys.query()\ .filter(UserApiKeys.user == self)\ - .filter(UserApiKeys.role == UserApiKeys.ROLE_FEED)\ - .all() + .filter(UserApiKeys.role == UserApiKeys.ROLE_FEED) + if cache: + feed_tokens = feed_tokens.options( + FromCache("long_term", "get_user_feed_token_%s" % self.user_id)) + + feed_tokens = feed_tokens.all() if feed_tokens: return feed_tokens[0].api_key return 'NO_FEED_TOKEN_AVAILABLE' diff --git a/rhodecode/model/user.py b/rhodecode/model/user.py --- a/rhodecode/model/user.py +++ b/rhodecode/model/user.py @@ -697,8 +697,6 @@ class UserModel(BaseModel): if k not in ['auth_tokens', 'permissions']: setattr(auth_user, k, v) - # few extras - setattr(auth_user, 'feed_token', dbuser.feed_token) except Exception: log.error(traceback.format_exc()) auth_user.is_authenticated = False