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