Changeset - df57253e965a
[Not reviewed]
beta
0 1 0
Mads Kiilerich - 13 years ago 2013-04-04 15:55:53
madski@unity3d.com
Transplanted from: 02da2762f3ee
invalidation: simplify get_prefix

str.split will always have a [0], and cache_key will always contain
repo_name=cache_args and the split will thus always return two elements
1 file changed with 1 insertions and 4 deletions:
0 comments (0 inline, 0 general)
rhodecode/model/db.py
Show inline comments
 
@@ -1635,52 +1635,49 @@ class CacheInvalidation(Base, BaseModel)
 
    # cache_id, not used
 
    cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
 
    # cache_key as created by _get_cache_key
 
    cache_key = Column("cache_key", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
 
    # cache_args is a repo_name
 
    cache_args = Column("cache_args", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
 
    # instance sets cache_active True when it is caching,
 
    # other instances set cache_active to False to indicate that this cache is invalid
 
    cache_active = Column("cache_active", Boolean(), nullable=True, unique=None, default=False)
 

	
 
    def __init__(self, cache_key, repo_name=''):
 
        self.cache_key = cache_key
 
        self.cache_args = repo_name
 
        self.cache_active = False
 

	
 
    def __unicode__(self):
 
        return u"<%s('%s:%s')>" % (self.__class__.__name__,
 
                                  self.cache_id, self.cache_key)
 

	
 
    def get_prefix(self):
 
        """
 
        Guess prefix that might have been used in _get_cache_key to generate self.cache_key .
 
        Only used for informational purposes in repo_edit.html .
 
        """
 
        _split = self.cache_key.split(self.cache_args, 1)
 
        if len(_split) == 2:
 
            return _split[0]
 
        return ''
 
        return self.cache_key.split(self.cache_args, 1)[0]
 

	
 
    @classmethod
 
    def _get_cache_key(cls, key):
 
        """
 
        Wrapper for generating a unique cache key for this instance and "key".
 
        key must / will start with a repo_name which will be stored in .cache_args .
 
        """
 
        import rhodecode
 
        prefix = rhodecode.CONFIG.get('instance_id', '')
 
        return "%s%s" % (prefix, key)
 

	
 
    @classmethod
 
    def _get_or_create_inv_obj(cls, key, repo_name):
 
        inv_obj = Session().query(cls).filter(cls.cache_key == key).scalar()
 
        if not inv_obj:
 
            try:
 
                inv_obj = CacheInvalidation(key, repo_name)
 
                Session().add(inv_obj)
 
                Session().commit()
 
            except Exception:
 
                log.error(traceback.format_exc())
 
                Session().rollback()
 
        return inv_obj
 

	
0 comments (0 inline, 0 general)