changeset 5533:aa1891074dd6

cache: when invalidating a cache, always just delete all 'live cache' records instead of marking them inactive Keep it simple. Adding the record again might be slightly more expensive than just updating the active flag but instead we get get a simpler model and automatic cleanup without using the cache-keys paster command.
author Mads Kiilerich <madski@unity3d.com>
date Thu, 08 Oct 2015 23:21:58 +0200
parents 92220cd013b0
children 55ccfc66479d
files kallithea/controllers/admin/repos.py kallithea/controllers/admin/settings.py kallithea/model/db.py kallithea/model/scm.py kallithea/tests/other/manual_test_vcs_operations.py
diffstat 5 files changed, 10 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/controllers/admin/repos.py	Thu Oct 08 23:21:58 2015 +0200
+++ b/kallithea/controllers/admin/repos.py	Thu Oct 08 23:21:58 2015 +0200
@@ -577,7 +577,7 @@
         c.active = 'caches'
         if request.POST:
             try:
-                ScmModel().mark_for_invalidation(repo_name, delete=True)
+                ScmModel().mark_for_invalidation(repo_name)
                 Session().commit()
                 h.flash(_('Cache invalidation successful'),
                         category='success')
--- a/kallithea/controllers/admin/settings.py	Thu Oct 08 23:21:58 2015 +0200
+++ b/kallithea/controllers/admin/settings.py	Thu Oct 08 23:21:58 2015 +0200
@@ -206,7 +206,7 @@
             if invalidate_cache:
                 log.debug('invalidating all repositories cache')
                 for repo in Repository.get_all():
-                    ScmModel().mark_for_invalidation(repo.repo_name, delete=True)
+                    ScmModel().mark_for_invalidation(repo.repo_name)
 
             filesystem_repos = ScmModel().repo_scan()
             added, removed = repo2db_mapper(filesystem_repos, rm_obsolete,
--- a/kallithea/model/db.py	Thu Oct 08 23:21:58 2015 +0200
+++ b/kallithea/model/db.py	Thu Oct 08 23:21:58 2015 +0200
@@ -2103,7 +2103,7 @@
         return "%s%s" % (prefix, key)
 
     @classmethod
-    def set_invalidate(cls, repo_name, delete=False):
+    def set_invalidate(cls, repo_name):
         """
         Mark all caches of a repo as invalid in the database.
         """
@@ -2114,11 +2114,7 @@
         for inv_obj in inv_objs:
             log.debug('marking %s key for invalidation based on repo_name=%s',
                       inv_obj, safe_str(repo_name))
-            if delete:
-                Session().delete(inv_obj)
-            else:
-                inv_obj.cache_active = False
-                Session().add(inv_obj)
+            Session().delete(inv_obj)
         Session().commit()
 
     @classmethod
--- a/kallithea/model/scm.py	Thu Oct 08 23:21:58 2015 +0200
+++ b/kallithea/model/scm.py	Thu Oct 08 23:21:58 2015 +0200
@@ -331,13 +331,13 @@
                 .filter(RepoGroup.group_parent_id == None).all()
         return [x for x in RepoGroupList(all_groups)]
 
-    def mark_for_invalidation(self, repo_name, delete=False):
+    def mark_for_invalidation(self, repo_name):
         """
         Mark caches of this repo invalid in the database.
 
         :param repo_name: the repo for which caches should be marked invalid
         """
-        CacheInvalidation.set_invalidate(repo_name, delete=delete)
+        CacheInvalidation.set_invalidate(repo_name)
         repo = Repository.get_by_repo_name(repo_name)
         if repo is not None:
             repo.update_changeset_cache()
--- a/kallithea/tests/other/manual_test_vcs_operations.py	Thu Oct 08 23:21:58 2015 +0200
+++ b/kallithea/tests/other/manual_test_vcs_operations.py	Thu Oct 08 23:21:58 2015 +0200
@@ -273,8 +273,8 @@
         stdout, stderr = _add_files_and_push('hg', DEST, files_no=1)
 
         key = CacheInvalidation.query().filter(CacheInvalidation.cache_key
-                                               ==HG_REPO).one()
-        self.assertEqual(key.cache_active, False)
+                                               ==HG_REPO).all()
+        self.assertEqual(key, [])
 
     def test_push_invalidates_cache_git(self):
         key = CacheInvalidation.query().filter(CacheInvalidation.cache_key
@@ -295,9 +295,8 @@
         _check_proper_git_push(stdout, stderr)
 
         key = CacheInvalidation.query().filter(CacheInvalidation.cache_key
-                                               ==GIT_REPO).one()
-        print CacheInvalidation.get_all()
-        self.assertEqual(key.cache_active, False)
+                                               ==GIT_REPO).all()
+        self.assertEqual(key, [])
 
     def test_push_wrong_credentials_hg(self):
         DEST = _get_tmp_dir()