changeset 1428:e5467730682b beta

fixed some issues with cache invalidation, and simplified invalidation codes
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 16 Jul 2011 12:02:14 +0200
parents ba697e2f71ff
children 864e4daef963
files rhodecode/model/db.py rhodecode/model/scm.py
diffstat 2 files changed, 11 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/model/db.py	Fri Jul 15 19:34:56 2011 +0200
+++ b/rhodecode/model/db.py	Sat Jul 16 12:02:14 2011 +0200
@@ -451,7 +451,6 @@
             .filter(CacheInvalidation.cache_active == False)\
             .scalar()
 
-    @property
     def set_invalidate(self):
         """
         set a cache for invalidation for this instance
@@ -476,18 +475,18 @@
         def _c(repo_name):
             return self.__get_instance()
 
+        # TODO: remove this trick when beaker 1.6 is released
+        # and have fixed this issue with not supporting unicode keys
+        rn = safe_str(self.repo_name)
+
         inv = self.invalidate
         if inv is not None:
-            region_invalidate(_c, None, self.repo_name)
-            #update our cache
+            region_invalidate(_c, None, rn)
+            # update our cache
             inv.cache_active = True
             Session.add(inv)
             Session.commit()
 
-        # TODO: remove this trick when beaker 1.6 is released
-        # and have fixed this issue
-        rn = safe_str(self.repo_name)
-
         return _c(rn)
 
     def __get_instance(self):
--- a/rhodecode/model/scm.py	Fri Jul 15 19:34:56 2011 +0200
+++ b/rhodecode/model/scm.py	Sat Jul 16 12:02:14 2011 +0200
@@ -66,10 +66,8 @@
 
 class CachedRepoList(object):
 
-    def __init__(self, db_repo_list, invalidation_list, repos_path,
-                 order_by=None):
+    def __init__(self, db_repo_list, repos_path, order_by=None):
         self.db_repo_list = db_repo_list
-        self.invalidation_list = invalidation_list
         self.repos_path = repos_path
         self.order_by = order_by
         self.reversed = (order_by or '').startswith('-')
@@ -81,22 +79,9 @@
         return '<%s (%s)>' % (self.__class__.__name__, self.__len__())
 
     def __iter__(self):
-        for db_repo in self.db_repo_list:
-            dbr = db_repo
-
-            # invalidate the repo cache if needed before getting the 
-            # scm instance
+        for dbr in self.db_repo_list:
 
-            scm_invalidate = False
-            if self.invalidation_list is not None:
-                scm_invalidate = dbr.repo_name in self.invalidation_list
-
-            if scm_invalidate:
-                log.info('invalidating cache for repository %s',
-                         dbr.repo_name)
-                db_repo.set_invalidate
-
-            scmr = db_repo.scm_instance_cached
+            scmr = dbr.scm_instance_cached
 
             #check permission at this level
             if not HasRepoPermissionAny('repository.read',
@@ -201,14 +186,7 @@
                         .filter(Repository.group_id == None)\
                         .order_by(Repository.repo_name).all()
 
-        #get the repositories that should be invalidated
-        invalidation_list = [str(x.cache_key) for x in \
-                             self.sa.query(CacheInvalidation.cache_key)\
-                             .filter(CacheInvalidation.cache_active == False)\
-                             .all()]
-
-        repo_iter = CachedRepoList(all_repos, invalidation_list,
-                                   repos_path=self.repos_path,
+        repo_iter = CachedRepoList(all_repos, repos_path=self.repos_path,
                                    order_by=sort_key)
 
         return repo_iter
@@ -225,7 +203,7 @@
             .filter(CacheInvalidation.cache_key == repo_name).scalar()
 
         if cache:
-            #mark this cache as inactive
+            # mark this cache as inactive
             cache.cache_active = False
         else:
             log.debug('cache key not found in invalidation db -> creating one')
@@ -394,20 +372,3 @@
             .scalar()
 
         return ret
-
-    def _mark_invalidated(self, cache_key):
-        """ Marks all occurrences of cache to invalidation as already
-        invalidated
-
-        :param cache_key:
-        """
-
-        if cache_key:
-            log.debug('marking %s as already invalidated', cache_key)
-        try:
-            cache_key.cache_active = True
-            self.sa.add(cache_key)
-            self.sa.commit()
-        except (DatabaseError,):
-            log.error(traceback.format_exc())
-            self.sa.rollback()