http_client: some reformatting
This commit is contained in:
parent
5316da6586
commit
dc3192df43
1 changed files with 24 additions and 14 deletions
|
|
@ -41,6 +41,7 @@ from rhodecode.lib import rc_cache
|
|||
from rhodecode.lib.rc_cache.utils import compute_key_from_params
|
||||
from rhodecode.lib.system_info import get_cert_path
|
||||
from rhodecode.lib.vcs import exceptions, CurlSession
|
||||
from rhodecode.lib.utils2 import str2bool
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
|
@ -242,20 +243,16 @@ class RemoteRepo(object):
|
|||
context_uid = wire.get('context')
|
||||
return context_uid, payload
|
||||
|
||||
@exceptions.map_vcs_exceptions
|
||||
def _call(self, name, *args, **kwargs):
|
||||
context_uid, payload = self._base_call(name, *args, **kwargs)
|
||||
url = self.url
|
||||
|
||||
start = time.time()
|
||||
|
||||
def get_local_cache(self, name, args):
|
||||
cache_on = False
|
||||
cache_key = ''
|
||||
local_cache_on = rhodecode.CONFIG.get('vcs.methods.cache')
|
||||
local_cache_on = str2bool(rhodecode.CONFIG.get('vcs.methods.cache'))
|
||||
|
||||
cache_methods = [
|
||||
'branches', 'tags', 'bookmarks',
|
||||
'is_large_file', 'is_binary', 'fctx_size', 'node_history', 'blob_raw_length',
|
||||
'is_large_file', 'is_binary',
|
||||
'fctx_size', 'stream:fctx_node_data', 'blob_raw_length',
|
||||
'node_history',
|
||||
'revision', 'tree_items',
|
||||
'ctx_list',
|
||||
'bulk_request',
|
||||
|
|
@ -267,6 +264,16 @@ class RemoteRepo(object):
|
|||
call_args = [a for a in args]
|
||||
cache_key = compute_key_from_params(repo_state_uid, name, *call_args)
|
||||
|
||||
return cache_on, cache_key
|
||||
|
||||
@exceptions.map_vcs_exceptions
|
||||
def _call(self, name, *args, **kwargs):
|
||||
context_uid, payload = self._base_call(name, *args, **kwargs)
|
||||
url = self.url
|
||||
|
||||
start = time.time()
|
||||
cache_on, cache_key = self.get_local_cache(name, args)
|
||||
|
||||
@self._cache_region.conditional_cache_on_arguments(
|
||||
namespace=self._cache_namespace, condition=cache_on and cache_key)
|
||||
def remote_call(_cache_key):
|
||||
|
|
@ -288,13 +295,16 @@ class RemoteRepo(object):
|
|||
url = self.stream_url
|
||||
|
||||
start = time.time()
|
||||
if self._call_with_logging:
|
||||
log.debug('Calling %s@%s with args:%.10240r. wire_context: %s',
|
||||
url, name, args, context_uid)
|
||||
cache_on, cache_key = self.get_local_cache(name, args)
|
||||
|
||||
result = _streaming_remote_call(url, payload, EXCEPTIONS_MAP, self._session,
|
||||
self.CHUNK_SIZE)
|
||||
# Cache is a problem because this is a stream
|
||||
def streaming_remote_call(_cache_key):
|
||||
if self._call_with_logging:
|
||||
log.debug('Calling %s@%s with args:%.10240r. wire_context: %s cache_on: %s',
|
||||
url, name, args, context_uid, cache_on)
|
||||
return _streaming_remote_call(url, payload, EXCEPTIONS_MAP, self._session, self.CHUNK_SIZE)
|
||||
|
||||
result = streaming_remote_call(cache_key)
|
||||
if self._call_with_logging:
|
||||
log.debug('Call %s@%s took: %.4fs. wire_context: %s',
|
||||
url, name, time.time()-start, context_uid)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue