# HG changeset patch # User Mads Kiilerich # Date 2015-01-06 00:54:36 # Node ID 3e5476843a1976ffd729e18a9d8217499cf6a698 # Parent ded49765b47a80220bee018c5839691e105cf271 cache invalidation: don't commit session if nothing changed It seems like a good idea to avoid unnecessary commits, considering we use expire_on_commit=True. It would perhaps be even better to postpone the commit to the end of the session - that is for another day. diff --git a/kallithea/model/db.py b/kallithea/model/db.py --- a/kallithea/model/db.py +++ b/kallithea/model/db.py @@ -2129,11 +2129,12 @@ class CacheInvalidation(Base, BaseModel) inv_obj = cls.query().filter(cls.cache_key == cache_key).scalar() if not inv_obj: inv_obj = CacheInvalidation(cache_key, repo_name) - was_valid = inv_obj.cache_active + if inv_obj.cache_active: + return True inv_obj.cache_active = True Session().add(inv_obj) Session().commit() - return was_valid + return False except Exception: log.error(traceback.format_exc()) Session().rollback()