Changeset - 7ae9939409ab
[Not reviewed]
beta
0 2 0
Marcin Kuzminski - 13 years ago 2012-11-30 00:09:04
marcin@python-works.com
Use ThreadLocal storage for dulwich cached repos, finally fixes issues on concurent opening git pack files via dulwich
2 files changed with 20 insertions and 2 deletions:
0 comments (0 inline, 0 general)
rhodecode/lib/vcs/backends/git/repository.py
Show inline comments
 
@@ -29,7 +29,7 @@ from rhodecode.lib.vcs.exceptions import
 
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
rhodecode/lib/vcs/utils/lazy.py
Show inline comments
 
@@ -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
 

	
0 comments (0 inline, 0 general)