##// END OF EJS Templates
caches: ensure we don't use non-ascii characters in cache keys....
marcink -
r1749:8c35f24d default
parent child Browse files
Show More
@@ -1045,8 +1045,8 b' class AuthUser(object):'
1045 default_ips = UserIpMap.query().filter(
1045 default_ips = UserIpMap.query().filter(
1046 UserIpMap.user == User.get_default_user(cache=True))
1046 UserIpMap.user == User.get_default_user(cache=True))
1047 if cache:
1047 if cache:
1048 default_ips = default_ips.options(FromCache("sql_cache_short",
1048 default_ips = default_ips.options(
1049 "get_user_ips_default"))
1049 FromCache("sql_cache_short", "get_user_ips_default"))
1050
1050
1051 # populate from default user
1051 # populate from default user
1052 for ip in default_ips:
1052 for ip in default_ips:
@@ -1059,8 +1059,8 b' class AuthUser(object):'
1059
1059
1060 user_ips = UserIpMap.query().filter(UserIpMap.user_id == user_id)
1060 user_ips = UserIpMap.query().filter(UserIpMap.user_id == user_id)
1061 if cache:
1061 if cache:
1062 user_ips = user_ips.options(FromCache("sql_cache_short",
1062 user_ips = user_ips.options(
1063 "get_user_ips_%s" % user_id))
1063 FromCache("sql_cache_short", "get_user_ips_%s" % user_id))
1064
1064
1065 for ip in user_ips:
1065 for ip in user_ips:
1066 try:
1066 try:
@@ -761,9 +761,9 b' class User(Base, BaseModel):'
761 if val:
761 if val:
762 return val
762 return val
763 else:
763 else:
764 cache_key = "get_user_by_name_%s" % _hash_key(username)
764 q = q.options(
765 q = q.options(
765 FromCache("sql_cache_short",
766 FromCache("sql_cache_short", cache_key))
766 "get_user_by_name_%s" % _hash_key(username)))
767
767
768 return q.scalar()
768 return q.scalar()
769
769
@@ -774,8 +774,8 b' class User(Base, BaseModel):'
774 .filter(or_(UserApiKeys.expires == -1,
774 .filter(or_(UserApiKeys.expires == -1,
775 UserApiKeys.expires >= time.time()))
775 UserApiKeys.expires >= time.time()))
776 if cache:
776 if cache:
777 q = q.options(FromCache("sql_cache_short",
777 q = q.options(
778 "get_auth_token_%s" % auth_token))
778 FromCache("sql_cache_short", "get_auth_token_%s" % auth_token))
779
779
780 match = q.first()
780 match = q.first()
781 if match:
781 if match:
@@ -790,9 +790,10 b' class User(Base, BaseModel):'
790 else:
790 else:
791 q = cls.query().filter(cls.email == email)
791 q = cls.query().filter(cls.email == email)
792
792
793 email_key = _hash_key(email)
793 if cache:
794 if cache:
794 q = q.options(FromCache("sql_cache_short",
795 q = q.options(
795 "get_email_key_%s" % _hash_key(email)))
796 FromCache("sql_cache_short", "get_email_key_%s" % email_key))
796
797
797 ret = q.scalar()
798 ret = q.scalar()
798 if ret is None:
799 if ret is None:
@@ -804,8 +805,8 b' class User(Base, BaseModel):'
804 q = q.filter(UserEmailMap.email == email)
805 q = q.filter(UserEmailMap.email == email)
805 q = q.options(joinedload(UserEmailMap.user))
806 q = q.options(joinedload(UserEmailMap.user))
806 if cache:
807 if cache:
807 q = q.options(FromCache("sql_cache_short",
808 q = q.options(
808 "get_email_map_key_%s" % email))
809 FromCache("sql_cache_short", "get_email_map_key_%s" % email_key))
809 ret = getattr(q.scalar(), 'user', None)
810 ret = getattr(q.scalar(), 'user', None)
810
811
811 return ret
812 return ret
@@ -1195,17 +1196,16 b' class UserGroup(Base, BaseModel):'
1195 else:
1196 else:
1196 q = cls.query().filter(cls.users_group_name == group_name)
1197 q = cls.query().filter(cls.users_group_name == group_name)
1197 if cache:
1198 if cache:
1198 q = q.options(FromCache(
1199 q = q.options(
1199 "sql_cache_short",
1200 FromCache("sql_cache_short", "get_group_%s" % _hash_key(group_name)))
1200 "get_group_%s" % _hash_key(group_name)))
1201 return q.scalar()
1201 return q.scalar()
1202
1202
1203 @classmethod
1203 @classmethod
1204 def get(cls, user_group_id, cache=False):
1204 def get(cls, user_group_id, cache=False):
1205 user_group = cls.query()
1205 user_group = cls.query()
1206 if cache:
1206 if cache:
1207 user_group = user_group.options(FromCache("sql_cache_short",
1207 user_group = user_group.options(
1208 "get_users_group_%s" % user_group_id))
1208 FromCache("sql_cache_short", "get_users_group_%s" % user_group_id))
1209 return user_group.get(user_group_id)
1209 return user_group.get(user_group_id)
1210
1210
1211 def permissions(self, with_admins=True, with_owner=True):
1211 def permissions(self, with_admins=True, with_owner=True):
@@ -1546,9 +1546,9 b' class Repository(Base, BaseModel):'
1546 if val:
1546 if val:
1547 return val
1547 return val
1548 else:
1548 else:
1549 cache_key = "get_repo_by_name_%s" % _hash_key(repo_name)
1549 q = q.options(
1550 q = q.options(
1550 FromCache("sql_cache_short",
1551 FromCache("sql_cache_short", cache_key))
1551 "get_repo_by_name_%s" % _hash_key(repo_name)))
1552
1552
1553 return q.scalar()
1553 return q.scalar()
1554
1554
@@ -2204,9 +2204,9 b' class RepoGroup(Base, BaseModel):'
2204 else:
2204 else:
2205 gr = cls.query().filter(cls.group_name == group_name)
2205 gr = cls.query().filter(cls.group_name == group_name)
2206 if cache:
2206 if cache:
2207 gr = gr.options(FromCache(
2207 name_key = _hash_key(group_name)
2208 "sql_cache_short",
2208 gr = gr.options(
2209 "get_group_%s" % _hash_key(group_name)))
2209 FromCache("sql_cache_short", "get_group_%s" % name_key))
2210 return gr.scalar()
2210 return gr.scalar()
2211
2211
2212 @classmethod
2212 @classmethod
@@ -200,14 +200,14 b' class IntegrationModel(BaseModel):'
200 query = query.filter(or_(*clauses))
200 query = query.filter(or_(*clauses))
201
201
202 if cache:
202 if cache:
203 query = query.options(FromCache(
203 cache_key = "get_enabled_repo_integrations_%i" % event.repo.repo_id
204 "sql_cache_short",
204 query = query.options(
205 "get_enabled_repo_integrations_%i" % event.repo.repo_id))
205 FromCache("sql_cache_short", cache_key))
206 else: # only global integrations
206 else: # only global integrations
207 query = query.filter(global_integrations_filter)
207 query = query.filter(global_integrations_filter)
208 if cache:
208 if cache:
209 query = query.options(FromCache(
209 query = query.options(
210 "sql_cache_short", "get_enabled_global_integrations"))
210 FromCache("sql_cache_short", "get_enabled_global_integrations"))
211
211
212 result = query.all()
212 result = query.all()
213 return result No newline at end of file
213 return result
@@ -44,7 +44,7 b' from rhodecode.lib.utils2 import ('
44 get_current_rhodecode_user, safe_int, datetime_to_time, action_logger_generic)
44 get_current_rhodecode_user, safe_int, datetime_to_time, action_logger_generic)
45 from rhodecode.lib.vcs.backends import get_backend
45 from rhodecode.lib.vcs.backends import get_backend
46 from rhodecode.model import BaseModel
46 from rhodecode.model import BaseModel
47 from rhodecode.model.db import (
47 from rhodecode.model.db import (_hash_key,
48 Repository, UserRepoToPerm, UserGroupRepoToPerm, UserRepoGroupToPerm,
48 Repository, UserRepoToPerm, UserGroupRepoToPerm, UserRepoGroupToPerm,
49 UserGroupRepoGroupToPerm, User, Permission, Statistics, UserGroup,
49 UserGroupRepoGroupToPerm, User, Permission, Statistics, UserGroup,
50 RepoGroup, RepositoryField)
50 RepoGroup, RepositoryField)
@@ -99,8 +99,8 b' class RepoModel(BaseModel):'
99 .filter(Repository.repo_id == repo_id)
99 .filter(Repository.repo_id == repo_id)
100
100
101 if cache:
101 if cache:
102 repo = repo.options(FromCache("sql_cache_short",
102 repo = repo.options(
103 "get_repo_%s" % repo_id))
103 FromCache("sql_cache_short", "get_repo_%s" % repo_id))
104 return repo.scalar()
104 return repo.scalar()
105
105
106 def get_repo(self, repository):
106 def get_repo(self, repository):
@@ -111,8 +111,9 b' class RepoModel(BaseModel):'
111 .filter(Repository.repo_name == repo_name)
111 .filter(Repository.repo_name == repo_name)
112
112
113 if cache:
113 if cache:
114 repo = repo.options(FromCache("sql_cache_short",
114 name_key = _hash_key(repo_name)
115 "get_repo_%s" % repo_name))
115 repo = repo.options(
116 FromCache("sql_cache_short", "get_repo_%s" % name_key))
116 return repo.scalar()
117 return repo.scalar()
117
118
118 def _extract_id_from_repo_name(self, repo_name):
119 def _extract_id_from_repo_name(self, repo_name):
@@ -35,7 +35,7 b' from zope.cachedescriptors.property impo'
35
35
36 from rhodecode import events
36 from rhodecode import events
37 from rhodecode.model import BaseModel
37 from rhodecode.model import BaseModel
38 from rhodecode.model.db import (
38 from rhodecode.model.db import (_hash_key,
39 RepoGroup, UserRepoGroupToPerm, User, Permission, UserGroupRepoGroupToPerm,
39 RepoGroup, UserRepoGroupToPerm, User, Permission, UserGroupRepoGroupToPerm,
40 UserGroup, Repository)
40 UserGroup, Repository)
41 from rhodecode.model.settings import VcsSettingsModel, SettingsModel
41 from rhodecode.model.settings import VcsSettingsModel, SettingsModel
@@ -73,8 +73,9 b' class RepoGroupModel(BaseModel):'
73 .filter(RepoGroup.group_name == repo_group_name)
73 .filter(RepoGroup.group_name == repo_group_name)
74
74
75 if cache:
75 if cache:
76 repo = repo.options(FromCache(
76 name_key = _hash_key(repo_group_name)
77 "sql_cache_short", "get_repo_group_%s" % repo_group_name))
77 repo = repo.options(
78 FromCache("sql_cache_short", "get_repo_group_%s" % name_key))
78 return repo.scalar()
79 return repo.scalar()
79
80
80 def get_default_create_personal_repo_group(self):
81 def get_default_create_personal_repo_group(self):
@@ -40,7 +40,7 b' from rhodecode.lib.utils2 import ('
40 from rhodecode.lib.caching_query import FromCache
40 from rhodecode.lib.caching_query import FromCache
41 from rhodecode.model import BaseModel
41 from rhodecode.model import BaseModel
42 from rhodecode.model.auth_token import AuthTokenModel
42 from rhodecode.model.auth_token import AuthTokenModel
43 from rhodecode.model.db import (
43 from rhodecode.model.db import (_hash_key,
44 or_, joinedload, User, UserToPerm, UserEmailMap, UserIpMap, UserLog)
44 or_, joinedload, User, UserToPerm, UserEmailMap, UserIpMap, UserLog)
45 from rhodecode.lib.exceptions import (
45 from rhodecode.lib.exceptions import (
46 DefaultUserException, UserOwnsReposException, UserOwnsRepoGroupsException,
46 DefaultUserException, UserOwnsReposException, UserOwnsRepoGroupsException,
@@ -58,8 +58,8 b' class UserModel(BaseModel):'
58 def get(self, user_id, cache=False):
58 def get(self, user_id, cache=False):
59 user = self.sa.query(User)
59 user = self.sa.query(User)
60 if cache:
60 if cache:
61 user = user.options(FromCache("sql_cache_short",
61 user = user.options(
62 "get_user_%s" % user_id))
62 FromCache("sql_cache_short", "get_user_%s" % user_id))
63 return user.get(user_id)
63 return user.get(user_id)
64
64
65 def get_user(self, user):
65 def get_user(self, user):
@@ -112,8 +112,9 b' class UserModel(BaseModel):'
112 user = self.sa.query(User)\
112 user = self.sa.query(User)\
113 .filter(User.username == username)
113 .filter(User.username == username)
114 if cache:
114 if cache:
115 user = user.options(FromCache("sql_cache_short",
115 name_key = _hash_key(username)
116 "get_user_%s" % username))
116 user = user.options(
117 FromCache("sql_cache_short", "get_user_%s" % name_key))
117 return user.scalar()
118 return user.scalar()
118
119
119 def get_by_email(self, email, cache=False, case_insensitive=False):
120 def get_by_email(self, email, cache=False, case_insensitive=False):
@@ -87,8 +87,8 b' def vcscontroller(pylonsapp, config_stub'
87 def _remove_default_user_from_query_cache():
87 def _remove_default_user_from_query_cache():
88 user = User.get_default_user(cache=True)
88 user = User.get_default_user(cache=True)
89 query = Session().query(User).filter(User.username == user.username)
89 query = Session().query(User).filter(User.username == user.username)
90 query = query.options(FromCache(
90 query = query.options(
91 "sql_cache_short", "get_user_%s" % _hash_key(user.username)))
91 FromCache("sql_cache_short", "get_user_%s" % _hash_key(user.username)))
92 query.invalidate()
92 query.invalidate()
93 Session().expire(user)
93 Session().expire(user)
94
94
General Comments 0
You need to be logged in to leave comments. Login now