Changeset - e8aff2016d86
[Not reviewed]
beta
0 1 0
Mads Kiilerich - 13 years ago 2013-04-04 15:55:53
madski@unity3d.com
Transplanted from: 39082927e235
invalidation: inline _get_or_create_inv_obj
1 file changed with 11 insertions and 15 deletions:
0 comments (0 inline, 0 general)
rhodecode/model/db.py
Show inline comments
 
@@ -1669,19 +1669,6 @@ class CacheInvalidation(Base, BaseModel)
 
        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
 

	
 
    @classmethod
 
    def invalidate(cls, key):
 
        """
 
        Returns Invalidation object if the local cache with the given key is invalid,
 
@@ -1693,9 +1680,18 @@ class CacheInvalidation(Base, BaseModel)
 
        repo_name = remove_suffix(repo_name, '_ATOM')
 

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

	
 
        if inv_obj and not inv_obj.cache_active:
 
        if not inv_obj.cache_active:
 
            # `cache_active = False` means that this cache
 
            # no longer is valid
 
            return inv_obj
0 comments (0 inline, 0 general)