##// END OF EJS Templates
Added cache options to some db getters
marcink -
r1665:36f77a46 beta
parent child Browse files
Show More
@@ -305,15 +305,25 b' class User(Base, BaseModel):'
305 return self.__class__.__name__
305 return self.__class__.__name__
306
306
307 @classmethod
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 if case_insensitive:
309 if case_insensitive:
310 return Session.query(cls).filter(cls.username.ilike(username)).scalar()
310 q = cls.query().filter(cls.username.ilike(username))
311 else:
311 else:
312 return Session.query(cls).filter(cls.username == username).scalar()
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 @classmethod
319 @classmethod
315 def get_by_api_key(cls, api_key):
320 def get_by_api_key(cls, api_key, cache=False):
316 return cls.query().filter(cls.api_key == api_key).one()
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 def update_lastlogin(self):
328 def update_lastlogin(self):
319 """Update user lastlogin"""
329 """Update user lastlogin"""
@@ -1083,6 +1093,7 b' class CacheInvalidation(Base, BaseModel)'
1083 Session.add(inv_obj)
1093 Session.add(inv_obj)
1084 Session.commit()
1094 Session.commit()
1085
1095
1096
1086 class DbMigrateVersion(Base, BaseModel):
1097 class DbMigrateVersion(Base, BaseModel):
1087 __tablename__ = 'db_migrate_version'
1098 __tablename__ = 'db_migrate_version'
1088 __table_args__ = {'extend_existing':True}
1099 __table_args__ = {'extend_existing':True}
General Comments 0
You need to be logged in to leave comments. Login now