Show More
@@ -37,6 +37,8 b' import requests' | |||
|
37 | 37 | from requests.packages.urllib3.util.retry import Retry |
|
38 | 38 | |
|
39 | 39 | import rhodecode |
|
40 | from rhodecode.lib import rc_cache | |
|
41 | from rhodecode.lib.rc_cache.utils import compute_key_from_params | |
|
40 | 42 | from rhodecode.lib.system_info import get_cert_path |
|
41 | 43 | from rhodecode.lib.vcs import exceptions, CurlSession |
|
42 | 44 | |
@@ -127,7 +129,6 b' class ServiceConnection(object):' | |||
|
127 | 129 | def __getattr__(self, name): |
|
128 | 130 | def f(*args, **kwargs): |
|
129 | 131 | return self._call(name, *args, **kwargs) |
|
130 | ||
|
131 | 132 | return f |
|
132 | 133 | |
|
133 | 134 | @exceptions.map_vcs_exceptions |
@@ -150,6 +151,12 b' class RemoteVCSMaker(object):' | |||
|
150 | 151 | self._session_factory = session_factory |
|
151 | 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 | 160 | def __call__(self, path, repo_id, config, with_wire=None): |
|
154 | 161 | log.debug('%s RepoMaker call on %s', self.backend_type.upper(), path) |
|
155 | 162 | return RemoteRepo(path, repo_id, config, self, with_wire=with_wire) |
@@ -178,6 +185,8 b' class RemoteRepo(object):' | |||
|
178 | 185 | self.url = remote_maker.url |
|
179 | 186 | self.stream_url = remote_maker.stream_url |
|
180 | 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 | 191 | with_wire = with_wire or {} |
|
183 | 192 | |
@@ -233,11 +242,22 b' class RemoteRepo(object):' | |||
|
233 | 242 | url = self.url |
|
234 | 243 | |
|
235 | 244 | start = time.time() |
|
245 | ||
|
246 | cache_on = False | |
|
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]) | |
|
251 | ||
|
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): | |
|
236 | 255 | if self._call_with_logging: |
|
237 | log.debug('Calling %s@%s with args:%.10240r. wire_context: %s', | |
|
238 | url, name, args, context_uid) | |
|
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) | |
|
239 | 259 | |
|
240 | result = _remote_call(url, payload, EXCEPTIONS_MAP, self._session) | |
|
260 | result = remote_call(cache_key) | |
|
241 | 261 | if self._call_with_logging: |
|
242 | 262 | log.debug('Call %s@%s took: %.4fs. wire_context: %s', |
|
243 | 263 | url, name, time.time()-start, context_uid) |
General Comments 0
You need to be logged in to leave comments.
Login now