# HG changeset patch # User Mads Kiilerich # Date 1365083753 -7200 # Node ID e8aff2016d869bbfd20913422e0162f4047bde12 # Parent df57253e965af547d416414912e1394d77ed4f6c invalidation: inline _get_or_create_inv_obj diff -r df57253e965a -r e8aff2016d86 rhodecode/model/db.py --- a/rhodecode/model/db.py Thu Apr 04 15:55:53 2013 +0200 +++ b/rhodecode/model/db.py Thu Apr 04 15:55:53 2013 +0200 @@ -1669,19 +1669,6 @@ 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 @@ 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