aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Kuzminski <marcin@python-works.com>2012-11-30 00:09:04 +0100
committerMarcin Kuzminski <marcin@python-works.com>2012-11-30 00:09:04 +0100
commite37989ef78e4362ff137f13aa296b77a6cebe809 (patch)
tree22d376b233962fc794b9acdb5cde4af21b205014
parentd4eb353fd0790f03479581dddf510b525f5ccc06 (diff)
Use ThreadLocal storage for dulwich cached repos, finally fixes issues on concurent opening git pack files via dulwich
--HG-- branch : beta
-rw-r--r--rhodecode/lib/vcs/backends/git/repository.py4
-rw-r--r--rhodecode/lib/vcs/utils/lazy.py18
2 files changed, 20 insertions, 2 deletions
diff --git a/rhodecode/lib/vcs/backends/git/repository.py b/rhodecode/lib/vcs/backends/git/repository.py
index e4f6e0b0..61d8f600 100644
--- a/rhodecode/lib/vcs/backends/git/repository.py
+++ b/rhodecode/lib/vcs/backends/git/repository.py
@@ -29,7 +29,7 @@ from rhodecode.lib.vcs.exceptions import RepositoryError
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 @@ class GitRepository(BaseRepository):
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
diff --git a/rhodecode/lib/vcs/utils/lazy.py b/rhodecode/lib/vcs/utils/lazy.py
index 1a7df2d2..58db4332 100644
--- a/rhodecode/lib/vcs/utils/lazy.py
+++ b/rhodecode/lib/vcs/utils/lazy.py
@@ -26,3 +26,21 @@ class LazyProperty(object):
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
+