changeset 3420:a6bef3e8a361 beta

Update changeset cache should use non-cache version of repo if given attribute is empty, it's easier to controll how changesets are udpated The quick update logic in base controller get's cached version and updates, while any other call will use non-cached version
author Marcin Kuzminski <marcin@python-works.com>
date Fri, 01 Mar 2013 17:56:31 +0100
parents efc00d363d1e
children 21c96f652470
files rhodecode/model/db.py rhodecode/model/repo.py
diffstat 2 files changed, 12 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/model/db.py	Fri Mar 01 15:25:36 2013 +0100
+++ b/rhodecode/model/db.py	Fri Mar 01 17:56:31 2013 +0100
@@ -44,6 +44,7 @@
 from rhodecode.lib.vcs.utils.helpers import get_scm
 from rhodecode.lib.vcs.exceptions import VCSError
 from rhodecode.lib.vcs.utils.lazy import LazyProperty
+from rhodecode.lib.vcs.backends.base import EmptyChangeset
 
 from rhodecode.lib.utils2 import str2bool, safe_str, get_changeset_safe, \
     safe_unicode, remove_suffix, remove_prefix
@@ -1053,15 +1054,18 @@
         """
         from rhodecode.lib.vcs.backends.base import BaseChangeset
         if cs_cache is None:
-            cs_cache = self.get_changeset()
+            cs_cache = EmptyChangeset()
+            # use no-cache version here
+            scm_repo = self.scm_instance_no_cache
+            if scm_repo:
+                cs_cache = scm_repo.get_changeset()
+
         if isinstance(cs_cache, BaseChangeset):
             cs_cache = cs_cache.__json__()
 
-        if (cs_cache != self.changeset_cache
-            or not self.last_change
-            or not self.changeset_cache):
+        if (cs_cache != self.changeset_cache or not self.changeset_cache):
             _default = datetime.datetime.fromtimestamp(0)
-            last_change = cs_cache.get('date') or self.last_change or _default
+            last_change = cs_cache.get('date') or _default
             log.debug('updated repo %s with new cs cache %s' % (self, cs_cache))
             self.updated_on = last_change
             self.changeset_cache = cs_cache
@@ -1188,7 +1192,8 @@
         repo_full_path = self.repo_full_path
         try:
             alias = get_scm(repo_full_path)[0]
-            log.debug('Creating instance of %s repository' % alias)
+            log.debug('Creating instance of %s repository from %s'
+                      % (alias, repo_full_path))
             backend = get_backend(alias)
         except VCSError:
             log.error(traceback.format_exc())
--- a/rhodecode/model/repo.py	Fri Mar 01 15:25:36 2013 +0100
+++ b/rhodecode/model/repo.py	Fri Mar 01 17:56:31 2013 +0100
@@ -149,11 +149,7 @@
         if not repositories:
             repositories = Repository.getAll()
         for repo in repositories:
-            scm_repo = repo.scm_instance_no_cache
-            last_cs = EmptyChangeset()
-            if scm_repo:
-                last_cs = scm_repo.get_changeset()
-            repo.update_changeset_cache(last_cs)
+            repo.update_changeset_cache()
 
     def get_repos_as_dict(self, repos_list=None, admin=False, perm_check=True,
                           super_user_actions=False):