From 2525df1b8e49ad158753854c77f52954245e42a5 Mon Sep 17 00:00:00 2001 From: Marcin Kuzminski Date: Tue, 8 Oct 2019 11:34:33 +0200 Subject: [PATCH] cache exc store, and use glob.glob for scaning exc store --- rhodecode/lib/exc_tracking.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/rhodecode/lib/exc_tracking.py b/rhodecode/lib/exc_tracking.py index 09591cf1..47163a25 100644 --- a/rhodecode/lib/exc_tracking.py +++ b/rhodecode/lib/exc_tracking.py @@ -25,6 +25,7 @@ import msgpack import logging import traceback import tempfile +import glob log = logging.getLogger(__name__) @@ -50,13 +51,20 @@ def exc_serialize(exc_id, tb, exc_type): def exc_unserialize(tb): return msgpack.unpackb(tb) +_exc_store = None + def get_exc_store(): """ Get and create exception store if it's not existing """ + global _exc_store import rhodecode as app + if _exc_store is not None: + # quick global cache + return _exc_store + exc_store_dir = app.CONFIG.get('exception_tracker.store_path', '') or tempfile.gettempdir() _exc_store_path = os.path.join(exc_store_dir, exc_store_dir_name) @@ -64,6 +72,8 @@ def get_exc_store(): if not os.path.isdir(_exc_store_path): os.makedirs(_exc_store_path) log.debug('Initializing exceptions store at %s', _exc_store_path) + _exc_store = _exc_store_path + return _exc_store_path @@ -119,16 +129,12 @@ def _find_exc_file(exc_id, prefix=global_prefix): # search without a prefix exc_id = '{}'.format(exc_id) - # we need to search the store for such start pattern as above - for fname in os.listdir(exc_store_path): - if fname.startswith(exc_id): - exc_id = os.path.join(exc_store_path, fname) - break - continue - else: - exc_id = None + found_exc_id = None + matches = glob.glob(os.path.join(exc_store_path, exc_id) + '*') + if matches: + found_exc_id = matches[0] - return exc_id + return found_exc_id def _read_exception(exc_id, prefix):