##// END OF EJS Templates
vcs: experimental local cache for methods
super-admin -
r4744:1a8b414c default
parent child
Show More
@@ -37,6 +37,8 import requests
37 from requests.packages.urllib3.util.retry import Retry
37 from requests.packages.urllib3.util.retry import Retry
38
38
39 import rhodecode
39 import rhodecode
40 from rhodecode.lib import rc_cache
41 from rhodecode.lib.rc_cache.utils import compute_key_from_params
40 from rhodecode.lib.system_info import get_cert_path
42 from rhodecode.lib.system_info import get_cert_path
41 from rhodecode.lib.vcs import exceptions, CurlSession
43 from rhodecode.lib.vcs import exceptions, CurlSession
42
44
@@ -127,7 +129,6 class ServiceConnection(object):
127 def __getattr__(self, name):
129 def __getattr__(self, name):
128 def f(*args, **kwargs):
130 def f(*args, **kwargs):
129 return self._call(name, *args, **kwargs)
131 return self._call(name, *args, **kwargs)
130
131 return f
132 return f
132
133
133 @exceptions.map_vcs_exceptions
134 @exceptions.map_vcs_exceptions
@@ -150,6 +151,12 class RemoteVCSMaker(object):
150 self._session_factory = session_factory
151 self._session_factory = session_factory
151 self.backend_type = backend_type
152 self.backend_type = backend_type
152
153
154 @classmethod
155 def init_cache_region(cls, repo_id):
156 cache_namespace_uid = 'cache_repo.{}'.format(repo_id)
157 region = rc_cache.get_or_create_region('cache_repo', cache_namespace_uid)
158 return region, cache_namespace_uid
159
153 def __call__(self, path, repo_id, config, with_wire=None):
160 def __call__(self, path, repo_id, config, with_wire=None):
154 log.debug('%s RepoMaker call on %s', self.backend_type.upper(), path)
161 log.debug('%s RepoMaker call on %s', self.backend_type.upper(), path)
155 return RemoteRepo(path, repo_id, config, self, with_wire=with_wire)
162 return RemoteRepo(path, repo_id, config, self, with_wire=with_wire)
@@ -178,6 +185,8 class RemoteRepo(object):
178 self.url = remote_maker.url
185 self.url = remote_maker.url
179 self.stream_url = remote_maker.stream_url
186 self.stream_url = remote_maker.stream_url
180 self._session = remote_maker._session_factory()
187 self._session = remote_maker._session_factory()
188 self._cache_region, self._cache_namespace = \
189 remote_maker.init_cache_region(repo_id)
181
190
182 with_wire = with_wire or {}
191 with_wire = with_wire or {}
183
192
@@ -233,11 +242,22 class RemoteRepo(object):
233 url = self.url
242 url = self.url
234
243
235 start = time.time()
244 start = time.time()
236 if self._call_with_logging:
245
237 log.debug('Calling %s@%s with args:%.10240r. wire_context: %s',
246 cache_on = False
238 url, name, args, context_uid)
247 cache_key = ''
248 if name in ['is_large_file', 'is_binary', 'fctx_size', 'bulk_request']:
249 cache_on = True and rhodecode.CONFIG.get('vcs.methods.cache')
250 cache_key = compute_key_from_params(name, args[0], args[1])
239
251
240 result = _remote_call(url, payload, EXCEPTIONS_MAP, self._session)
252 @self._cache_region.conditional_cache_on_arguments(
253 namespace=self._cache_namespace, condition=cache_on and cache_key)
254 def remote_call(_cache_key):
255 if self._call_with_logging:
256 log.debug('Calling %s@%s with args:%.10240r. wire_context: %s cache_on: %s',
257 url, name, args, context_uid, cache_on)
258 return _remote_call(url, payload, EXCEPTIONS_MAP, self._session)
259
260 result = remote_call(cache_key)
241 if self._call_with_logging:
261 if self._call_with_logging:
242 log.debug('Call %s@%s took: %.4fs. wire_context: %s',
262 log.debug('Call %s@%s took: %.4fs. wire_context: %s',
243 url, name, time.time()-start, context_uid)
263 url, name, time.time()-start, context_uid)
General Comments 0
You need to be logged in to leave comments. Login now