This commit is contained in:
krateng 2023-10-26 16:10:51 +02:00
parent 40d5d0da78
commit 21d1c061bf
3 changed files with 23 additions and 12 deletions

View File

@ -810,8 +810,9 @@ def start_db():
# create cached information
cached.update_medals()
cached.update_weekly()
# these are already run from the decorator!
#cached.update_medals()
#cached.update_weekly()
dbstatus['complete'] = True

View File

@ -8,25 +8,35 @@ from doreah.timing import Clock
from ..pkg_global.conf import data_dir
profiler = cProfile.Profile()
FULL_PROFILE = False
SINGLE_CALLS = False
# only save the last single call instead of adding up all calls
# of that function for more representative performance result
if SINGLE_CALLS:
profiler = cProfile.Profile()
def profile(func):
def newfunc(*args,**kwargs):
if FULL_PROFILE:
benchmarkfolder = data_dir['logs']("benchmarks")
os.makedirs(benchmarkfolder,exist_ok=True)
clock = Clock()
clock.start()
if FULL_PROFILE:
profiler.enable()
benchmarkfolder = data_dir['logs']("benchmarks")
os.makedirs(benchmarkfolder,exist_ok=True)
if not SINGLE_CALLS:
localprofiler = cProfile.Profile()
else:
localprofiler = profiler
localprofiler.enable()
result = func(*args,**kwargs)
if FULL_PROFILE:
profiler.disable()
localprofiler.disable()
seconds = clock.stop()
realfunc = func
@ -36,7 +46,7 @@ def profile(func):
if FULL_PROFILE:
targetfilename = os.path.join(benchmarkfolder,f"{realfunc.__name__}.stats")
try:
pstats.Stats(profiler).dump_stats(targetfilename)
pstats.Stats(localprofiler).dump_stats(targetfilename)
log(f"Saved benchmark as {targetfilename}")
except Exception:
log(f"Failed to save benchmark as {targetfilename}")

View File

@ -123,8 +123,8 @@ def dynamic_image():
if result['type'] == 'noimage' and result['value'] == 'wait':
# still being worked on
response.status = 503
response.set_header('Retry-After',5)
response.status = 202
response.set_header('Retry-After',15)
return
if result['type'] in ('url','localurl'):
redirect(result['value'],307)