##// END OF EJS Templates
caches: make gevent curl connection cache friendly....
marcink -
r2946:193b4eb7 default
parent child Browse files
Show More
@@ -176,7 +176,6 b' class BaseRepository(object):'
176 EMPTY_COMMIT_ID = '0' * 40
176 EMPTY_COMMIT_ID = '0' * 40
177
177
178 path = None
178 path = None
179 _remote = None
180
179
181 def __init__(self, repo_path, config=None, create=False, **kwargs):
180 def __init__(self, repo_path, config=None, create=False, **kwargs):
182 """
181 """
@@ -222,6 +221,10 b' class BaseRepository(object):'
222 return config
221 return config
223
222
224 @LazyProperty
223 @LazyProperty
224 def _remote(self):
225 raise NotImplementedError
226
227 @LazyProperty
225 def EMPTY_COMMIT(self):
228 def EMPTY_COMMIT(self):
226 return EmptyCommit(self.EMPTY_COMMIT_ID)
229 return EmptyCommit(self.EMPTY_COMMIT_ID)
227
230
@@ -62,8 +62,7 b' class GitRepository(BaseRepository):'
62
62
63 self.path = safe_str(os.path.abspath(repo_path))
63 self.path = safe_str(os.path.abspath(repo_path))
64 self.config = config if config else self.get_default_config()
64 self.config = config if config else self.get_default_config()
65 self._remote = connection.Git(
65 self.with_wire = with_wire
66 self.path, self.config, with_wire=with_wire)
67
66
68 self._init_repo(create, src_url, update_after_clone, bare)
67 self._init_repo(create, src_url, update_after_clone, bare)
69
68
@@ -71,6 +70,10 b' class GitRepository(BaseRepository):'
71 self._commit_ids = {}
70 self._commit_ids = {}
72
71
73 @LazyProperty
72 @LazyProperty
73 def _remote(self):
74 return connection.Git(self.path, self.config, with_wire=self.with_wire)
75
76 @LazyProperty
74 def bare(self):
77 def bare(self):
75 return self._remote.bare()
78 return self._remote.bare()
76
79
@@ -77,9 +77,7 b' class MercurialRepository(BaseRepository'
77 # special requirements
77 # special requirements
78 self.config = config if config else self.get_default_config(
78 self.config = config if config else self.get_default_config(
79 default=[('extensions', 'largefiles', '1')])
79 default=[('extensions', 'largefiles', '1')])
80
80 self.with_wire = with_wire
81 self._remote = connection.Hg(
82 self.path, self.config, with_wire=with_wire)
83
81
84 self._init_repo(create, src_url, update_after_clone)
82 self._init_repo(create, src_url, update_after_clone)
85
83
@@ -87,6 +85,10 b' class MercurialRepository(BaseRepository'
87 self._commit_ids = {}
85 self._commit_ids = {}
88
86
89 @LazyProperty
87 @LazyProperty
88 def _remote(self):
89 return connection.Hg(self.path, self.config, with_wire=self.with_wire)
90
91 @LazyProperty
90 def commit_ids(self):
92 def commit_ids(self):
91 """
93 """
92 Returns list of commit ids, in ascending order. Being lazy
94 Returns list of commit ids, in ascending order. Being lazy
@@ -72,11 +72,13 b' class SubversionRepository(base.BaseRepo'
72 **kwargs):
72 **kwargs):
73 self.path = safe_str(os.path.abspath(repo_path))
73 self.path = safe_str(os.path.abspath(repo_path))
74 self.config = config if config else self.get_default_config()
74 self.config = config if config else self.get_default_config()
75 self._remote = connection.Svn(
76 self.path, self.config)
77
75
78 self._init_repo(create, src_url)
76 self._init_repo(create, src_url)
79
77
78 @LazyProperty
79 def _remote(self):
80 return connection.Svn(self.path, self.config)
81
80 def _init_repo(self, create, src_url):
82 def _init_repo(self, create, src_url):
81 if create and os.path.exists(self.path):
83 if create and os.path.exists(self.path):
82 raise RepositoryError(
84 raise RepositoryError(
@@ -27,6 +27,7 b' class in a way that is compatible with g'
27 import logging
27 import logging
28 import gevent
28 import gevent
29 import pycurl
29 import pycurl
30 import greenlet
30
31
31 # Import everything from pycurl.
32 # Import everything from pycurl.
32 # This allows us to use this module as a drop in replacement of pycurl.
33 # This allows us to use this module as a drop in replacement of pycurl.
@@ -230,6 +231,12 b' class GeventCurl(object):'
230 This perform method is compatible with gevent because it uses gevent
231 This perform method is compatible with gevent because it uses gevent
231 synchronization mechanisms to wait for the request to finish.
232 synchronization mechanisms to wait for the request to finish.
232 """
233 """
234 if getattr(self._curl, 'waiter', None) is not None:
235 current = greenlet.getcurrent()
236 msg = 'This curl object is already used by another greenlet, {}, \n' \
237 'this is {}'.format(self._curl.waiter, current)
238 raise Exception(msg)
239
233 waiter = self._curl.waiter = Waiter()
240 waiter = self._curl.waiter = Waiter()
234 try:
241 try:
235 self._multi.add_handle(self._curl)
242 self._multi.add_handle(self._curl)
@@ -2339,8 +2339,11 b' class Repository(Base, BaseModel):'
2339 def get_instance_cached(repo_id):
2339 def get_instance_cached(repo_id):
2340 return self._get_instance()
2340 return self._get_instance()
2341
2341
2342 # we must use thread scoped cache here,
2343 # because each thread of gevent needs it's own connection and cache
2342 inv_context_manager = rc_cache.InvalidationContext(
2344 inv_context_manager = rc_cache.InvalidationContext(
2343 uid=cache_namespace_uid, invalidation_namespace=invalidation_namespace)
2345 uid=cache_namespace_uid, invalidation_namespace=invalidation_namespace,
2346 thread_scoped=True)
2344 with inv_context_manager as invalidation_context:
2347 with inv_context_manager as invalidation_context:
2345 args = (self.repo_id,)
2348 args = (self.repo_id,)
2346 # re-compute and store cache if we get invalidate signal
2349 # re-compute and store cache if we get invalidate signal
General Comments 0
You need to be logged in to leave comments. Login now