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