changeset 3684:e8aff2016d86 beta

invalidation: inline _get_or_create_inv_obj
author Mads Kiilerich <madski@unity3d.com>
date Thu, 04 Apr 2013 15:55:53 +0200
parents df57253e965a
children 02e1e270bf93
files rhodecode/model/db.py
diffstat 1 files changed, 11 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- 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