cache exc store, and use glob.glob for scaning exc store

This commit is contained in:
Marcin Kuzminski 2019-10-08 11:34:33 +02:00
parent ebc48676cb
commit 2525df1b8e

View file

@ -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):