Changeset - 36f77a46f291
[Not reviewed]
beta
0 1 0
Marcin Kuzminski - 14 years ago 2011-11-11 17:45:48
marcin@python-works.com
Added cache options to some db getters
1 file changed with 16 insertions and 5 deletions:
0 comments (0 inline, 0 general)
rhodecode/model/db.py
Show inline comments
 
@@ -305,15 +305,25 @@ class User(Base, BaseModel):
 
            return self.__class__.__name__
 

	
 
    @classmethod
 
    def get_by_username(cls, username, case_insensitive=False):
 
    def get_by_username(cls, username, case_insensitive=False, cache=False):
 
        if case_insensitive:
 
            return Session.query(cls).filter(cls.username.ilike(username)).scalar()
 
            q = cls.query().filter(cls.username.ilike(username))
 
        else:
 
            return Session.query(cls).filter(cls.username == username).scalar()
 
            q = cls.query().filter(cls.username == username)
 

	
 
        if cache:
 
            q = q.options(FromCache("sql_cache_short",
 
                                    "get_user_%s" % username))
 
        return q.scalar()
 

	
 
    @classmethod
 
    def get_by_api_key(cls, api_key):
 
        return cls.query().filter(cls.api_key == api_key).one()
 
    def get_by_api_key(cls, api_key, cache=False):
 
        q = cls.query().filter(cls.api_key == api_key)
 

	
 
        if cache:
 
            q = q.options(FromCache("sql_cache_short",
 
                                    "get_api_key_%s" % api_key))
 
        q.one()
 

	
 
    def update_lastlogin(self):
 
        """Update user lastlogin"""
 
@@ -1083,6 +1093,7 @@ class CacheInvalidation(Base, BaseModel)
 
        Session.add(inv_obj)
 
        Session.commit()
 

	
 

	
 
class DbMigrateVersion(Base, BaseModel):
 
    __tablename__ = 'db_migrate_version'
 
    __table_args__ = {'extend_existing':True}
0 comments (0 inline, 0 general)