Show More
@@ -305,15 +305,25 b' class User(Base, BaseModel):' | |||
|
305 | 305 | return self.__class__.__name__ |
|
306 | 306 | |
|
307 | 307 | @classmethod |
|
308 | def get_by_username(cls, username, case_insensitive=False): | |
|
308 | def get_by_username(cls, username, case_insensitive=False, cache=False): | |
|
309 | 309 | if case_insensitive: |
|
310 |
|
|
|
310 | q = cls.query().filter(cls.username.ilike(username)) | |
|
311 | 311 | else: |
|
312 |
|
|
|
312 | q = cls.query().filter(cls.username == username) | |
|
313 | ||
|
314 | if cache: | |
|
315 | q = q.options(FromCache("sql_cache_short", | |
|
316 | "get_user_%s" % username)) | |
|
317 | return q.scalar() | |
|
313 | 318 | |
|
314 | 319 | @classmethod |
|
315 | def get_by_api_key(cls, api_key): | |
|
316 |
|
|
|
320 | def get_by_api_key(cls, api_key, cache=False): | |
|
321 | q = cls.query().filter(cls.api_key == api_key) | |
|
322 | ||
|
323 | if cache: | |
|
324 | q = q.options(FromCache("sql_cache_short", | |
|
325 | "get_api_key_%s" % api_key)) | |
|
326 | q.one() | |
|
317 | 327 | |
|
318 | 328 | def update_lastlogin(self): |
|
319 | 329 | """Update user lastlogin""" |
@@ -1083,6 +1093,7 b' class CacheInvalidation(Base, BaseModel)' | |||
|
1083 | 1093 | Session.add(inv_obj) |
|
1084 | 1094 | Session.commit() |
|
1085 | 1095 | |
|
1096 | ||
|
1086 | 1097 | class DbMigrateVersion(Base, BaseModel): |
|
1087 | 1098 | __tablename__ = 'db_migrate_version' |
|
1088 | 1099 | __table_args__ = {'extend_existing':True} |
General Comments 0
You need to be logged in to leave comments.
Login now