changeset 3050:7ae9939409ab beta

Use ThreadLocal storage for dulwich cached repos, finally fixes issues on concurent opening git pack files via dulwich
author Marcin Kuzminski <marcin@python-works.com>
date Fri, 30 Nov 2012 00:09:04 +0100
parents 12b183c1628b
children 33d63f5cc48c
files rhodecode/lib/vcs/backends/git/repository.py rhodecode/lib/vcs/utils/lazy.py
diffstat 2 files changed, 20 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/lib/vcs/backends/git/repository.py	Thu Nov 29 22:23:44 2012 +0100
+++ b/rhodecode/lib/vcs/backends/git/repository.py	Fri Nov 30 00:09:04 2012 +0100
@@ -29,7 +29,7 @@
 from rhodecode.lib.vcs.exceptions import TagAlreadyExistError
 from rhodecode.lib.vcs.exceptions import TagDoesNotExistError
 from rhodecode.lib.vcs.utils import safe_unicode, makedate, date_fromtimestamp
-from rhodecode.lib.vcs.utils.lazy import LazyProperty
+from rhodecode.lib.vcs.utils.lazy import LazyProperty, ThreadLocalLazyProperty
 from rhodecode.lib.vcs.utils.ordered_dict import OrderedDict
 from rhodecode.lib.vcs.utils.paths import abspath
 from rhodecode.lib.vcs.utils.paths import get_user_home
@@ -63,7 +63,7 @@
             abspath(get_user_home(), '.gitconfig'),
         ]
 
-    @LazyProperty
+    @ThreadLocalLazyProperty
     def _repo(self):
         repo = Repo(self.path)
         #temporary set that to now at later we will move it to constructor
--- a/rhodecode/lib/vcs/utils/lazy.py	Thu Nov 29 22:23:44 2012 +0100
+++ b/rhodecode/lib/vcs/utils/lazy.py	Fri Nov 30 00:09:04 2012 +0100
@@ -26,3 +26,21 @@
             return self
         result = obj.__dict__[self.__name__] = self._func(obj)
         return result
+
+import threading
+
+
+class ThreadLocalLazyProperty(LazyProperty):
+    """
+    Same as above but uses thread local dict for cache storage.
+    """
+
+    def __get__(self, obj, klass=None):
+        if obj is None:
+            return self
+        if not hasattr(obj, '__tl_dict__'):
+            obj.__tl_dict__ = threading.local().__dict__
+
+        result = obj.__tl_dict__[self.__name__] = self._func(obj)
+        return result
+