##// END OF EJS Templates
caches: cleanup code...
super-admin -
r5009:4102d6ca default
parent child Browse files
Show More
@@ -693,12 +693,14 b' class User(Base, BaseModel):'
693 return [self.email] + [x.email for x in other]
693 return [self.email] + [x.email for x in other]
694
694
695 def emails_cached(self):
695 def emails_cached(self):
696 emails = []
697 if self.user_id != self.get_default_user_id():
696 emails = UserEmailMap.query()\
698 emails = UserEmailMap.query()\
697 .filter(UserEmailMap.user == self) \
699 .filter(UserEmailMap.user == self) \
698 .order_by(UserEmailMap.email_id.asc())
700 .order_by(UserEmailMap.email_id.asc())
699
701
700 emails = emails.options(
702 emails = emails.options(
701 FromCache("sql_cache_short", "get_user_{}_emails".format(self.user_id))
703 FromCache("sql_cache_short", f"get_user_{self.user_id}_emails")
702 )
704 )
703
705
704 return [self.email] + [x.email for x in emails]
706 return [self.email] + [x.email for x in emails]
@@ -724,7 +726,7 b' class User(Base, BaseModel):'
724 .filter(UserApiKeys.role == UserApiKeys.ROLE_FEED)
726 .filter(UserApiKeys.role == UserApiKeys.ROLE_FEED)
725 if cache:
727 if cache:
726 feed_tokens = feed_tokens.options(
728 feed_tokens = feed_tokens.options(
727 FromCache("sql_cache_short", "get_user_feed_token_%s" % self.user_id))
729 FromCache("sql_cache_short", f"get_user_feed_token_{self.user_id}"))
728
730
729 feed_tokens = feed_tokens.all()
731 feed_tokens = feed_tokens.all()
730 if feed_tokens:
732 if feed_tokens:
@@ -744,7 +746,7 b' class User(Base, BaseModel):'
744
746
745 if cache:
747 if cache:
746 artifacts_tokens = artifacts_tokens.options(
748 artifacts_tokens = artifacts_tokens.options(
747 FromCache("sql_cache_short", "get_user_artifact_token_%s" % self.user_id))
749 FromCache("sql_cache_short", f"get_user_artifact_token_{self.user_id}"))
748
750
749 artifacts_tokens = artifacts_tokens.all()
751 artifacts_tokens = artifacts_tokens.all()
750 if artifacts_tokens:
752 if artifacts_tokens:
@@ -777,7 +779,7 b' class User(Base, BaseModel):'
777 user = cls.query()
779 user = cls.query()
778 if cache:
780 if cache:
779 user = user.options(
781 user = user.options(
780 FromCache("sql_cache_short", "get_users_%s" % user_id))
782 FromCache("sql_cache_short", f"get_users_{user_id}"))
781 return user.get(user_id)
783 return user.get(user_id)
782
784
783 @classmethod
785 @classmethod
@@ -858,7 +860,7 b' class User(Base, BaseModel):'
858
860
859 @property
861 @property
860 def username_or_name_or_email(self):
862 def username_or_name_or_email(self):
861 full_name = self.full_name if self.full_name is not ' ' else None
863 full_name = self.full_name if self.full_name != ' ' else None
862 return self.username or full_name or self.email
864 return self.username or full_name or self.email
863
865
864 @property
866 @property
@@ -943,7 +945,7 b' class User(Base, BaseModel):'
943 UserApiKeys.expires >= time.time()))
945 UserApiKeys.expires >= time.time()))
944 if cache:
946 if cache:
945 q = q.options(
947 q = q.options(
946 FromCache("sql_cache_short", "get_auth_token_%s" % auth_token))
948 FromCache("sql_cache_short", f"get_auth_token_{auth_token}"))
947
949
948 match = q.first()
950 match = q.first()
949 if match:
951 if match:
@@ -961,7 +963,7 b' class User(Base, BaseModel):'
961 email_key = _hash_key(email)
963 email_key = _hash_key(email)
962 if cache:
964 if cache:
963 q = q.options(
965 q = q.options(
964 FromCache("sql_cache_short", "get_email_key_%s" % email_key))
966 FromCache("sql_cache_short", f"get_email_key_{email_key}"))
965
967
966 ret = q.scalar()
968 ret = q.scalar()
967 if ret is None:
969 if ret is None:
@@ -974,7 +976,7 b' class User(Base, BaseModel):'
974 q = q.options(joinedload(UserEmailMap.user))
976 q = q.options(joinedload(UserEmailMap.user))
975 if cache:
977 if cache:
976 q = q.options(
978 q = q.options(
977 FromCache("sql_cache_short", "get_email_map_key_%s" % email_key))
979 FromCache("sql_cache_short", f"get_email_map_key_{email_key}"))
978 ret = getattr(q.scalar(), 'user', None)
980 ret = getattr(q.scalar(), 'user', None)
979
981
980 return ret
982 return ret
@@ -1486,8 +1488,9 b' class UserGroup(Base, BaseModel):'
1486 else:
1488 else:
1487 q = cls.query().filter(cls.users_group_name == group_name)
1489 q = cls.query().filter(cls.users_group_name == group_name)
1488 if cache:
1490 if cache:
1491 name_key = _hash_key(group_name)
1489 q = q.options(
1492 q = q.options(
1490 FromCache("sql_cache_short", "get_group_%s" % _hash_key(group_name)))
1493 FromCache("sql_cache_short", f"get_group_{name_key}"))
1491 return q.scalar()
1494 return q.scalar()
1492
1495
1493 @classmethod
1496 @classmethod
@@ -107,7 +107,7 b' class RepoModel(BaseModel):'
107 if cache:
107 if cache:
108 name_key = _hash_key(repo_name)
108 name_key = _hash_key(repo_name)
109 repo = repo.options(
109 repo = repo.options(
110 FromCache("sql_cache_short", "get_repo_%s" % name_key))
110 FromCache("sql_cache_short", f"get_repo_{name_key}"))
111 return repo.scalar()
111 return repo.scalar()
112
112
113 def _extract_id_from_repo_name(self, repo_name):
113 def _extract_id_from_repo_name(self, repo_name):
@@ -80,7 +80,7 b' class RepoGroupModel(BaseModel):'
80 if cache:
80 if cache:
81 name_key = _hash_key(repo_group_name)
81 name_key = _hash_key(repo_group_name)
82 repo = repo.options(
82 repo = repo.options(
83 FromCache("sql_cache_short", "get_repo_group_%s" % name_key))
83 FromCache("sql_cache_short", f"get_repo_group_{name_key}"))
84 return repo.scalar()
84 return repo.scalar()
85
85
86 def get_default_create_personal_repo_group(self):
86 def get_default_create_personal_repo_group(self):
@@ -58,7 +58,7 b' class UserModel(BaseModel):'
58 user = self.sa.query(User)
58 user = self.sa.query(User)
59 if cache:
59 if cache:
60 user = user.options(
60 user = user.options(
61 FromCache("sql_cache_short", "get_user_%s" % user_id))
61 FromCache("sql_cache_short", f"get_user_{user_id}"))
62 return user.get(user_id)
62 return user.get(user_id)
63
63
64 def get_user(self, user):
64 def get_user(self, user):
@@ -118,7 +118,7 b' class UserModel(BaseModel):'
118 if cache:
118 if cache:
119 name_key = _hash_key(username)
119 name_key = _hash_key(username)
120 user = user.options(
120 user = user.options(
121 FromCache("sql_cache_short", "get_user_%s" % name_key))
121 FromCache("sql_cache_short", f"get_user_{name_key}"))
122 return user.scalar()
122 return user.scalar()
123
123
124 def get_by_email(self, email, cache=False, case_insensitive=False):
124 def get_by_email(self, email, cache=False, case_insensitive=False):
General Comments 0
You need to be logged in to leave comments. Login now