Show More
@@ -284,7 +284,7 b' class BaseModel(object):' | |||||
284 | @classmethod |
|
284 | @classmethod | |
285 | def get(cls, id_): |
|
285 | def get(cls, id_): | |
286 | if id_: |
|
286 | if id_: | |
287 |
return |
|
287 | return Session().get(cls, id_) | |
288 |
|
288 | |||
289 | @classmethod |
|
289 | @classmethod | |
290 | def get_or_404(cls, id_): |
|
290 | def get_or_404(cls, id_): | |
@@ -1077,11 +1077,11 b' class User(Base, BaseModel):' | |||||
1077 | if not user_id: |
|
1077 | if not user_id: | |
1078 | return |
|
1078 | return | |
1079 |
|
1079 | |||
1080 | user = cls.query() |
|
1080 | q = cls.select().where(cls.user_id == user_id) | |
1081 | if cache: |
|
1081 | if cache: | |
1082 |
|
|
1082 | q = q.options( | |
1083 | FromCache("sql_cache_short", f"get_users_{user_id}")) |
|
1083 | FromCache("sql_cache_short", f"get_users_{user_id}")) | |
1084 | return user.get(user_id) |
|
1084 | return cls.execute(q).scalar_one_or_none() | |
1085 |
|
1085 | |||
1086 | @classmethod |
|
1086 | @classmethod | |
1087 | def get_by_username(cls, username, case_insensitive=False, |
|
1087 | def get_by_username(cls, username, case_insensitive=False, |
@@ -54,11 +54,12 b' class UserModel(BaseModel):' | |||||
54 | cls = User |
|
54 | cls = User | |
55 |
|
55 | |||
56 | def get(self, user_id, cache=False): |
|
56 | def get(self, user_id, cache=False): | |
57 |
|
|
57 | cls = self.cls | |
|
58 | q = cls.select().where(cls.user_id == user_id) | |||
58 | if cache: |
|
59 | if cache: | |
59 |
|
|
60 | q = q.options( | |
60 | FromCache("sql_cache_short", f"get_user_{user_id}")) |
|
61 | FromCache("sql_cache_short", f"get_users_{user_id}")) | |
61 | return user.get(user_id) |
|
62 | return cls.execute(q).scalar_one_or_none() | |
62 |
|
63 | |||
63 | def get_user(self, user): |
|
64 | def get_user(self, user): | |
64 | return self._get_user(user) |
|
65 | return self._get_user(user) |
General Comments 0
You need to be logged in to leave comments.
Login now