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