diff --git a/maloja/database/__init__.py b/maloja/database/__init__.py index dc467e3..bfbfea0 100644 --- a/maloja/database/__init__.py +++ b/maloja/database/__init__.py @@ -634,7 +634,7 @@ def artist_info(dbconn=None,**keys): "topweeks":len([ week for week in ranges(step="week") if (week != twk) and any( (e.get('artist_id') == artist_id) and (e.get('rank') == 1) for e in - sqldb.count_scrobbles_by_artist(since=week.first_stamp(),to=week.last_stamp(),resolve_ids=False,dbconn=dbconn) + sqldb.count_scrobbles_by_artist(since=week.first_stamp(),to=week.last_stamp(),resolve_ids=False,associated=True,dbconn=dbconn) ) # we don't need to check the whole thing, just until rank is lower, but... well, its a list comprehension ]) @@ -864,9 +864,9 @@ def start_db(): with sqldb.engine.connect() as dbconn: with dbconn.begin(): for week in ranges(step='week'): - _ = sqldb.count_scrobbles_by_artist(since=week.first_stamp(),to=week.last_stamp(),resolve_ids=False,dbconn=dbconn) - _ = sqldb.count_scrobbles_by_track(since=week.first_stamp(),to=week.last_stamp(),resolve_ids=False,dbconn=dbconn) - _ = sqldb.count_scrobbles_by_album(since=week.first_stamp(),to=week.last_stamp(),resolve_ids=False,dbconn=dbconn) + sqldb.count_scrobbles_by_artist(since=week.first_stamp(),to=week.last_stamp(),resolve_ids=False,associated=True,dbconn=dbconn) + sqldb.count_scrobbles_by_track(since=week.first_stamp(),to=week.last_stamp(),resolve_ids=False,dbconn=dbconn) + sqldb.count_scrobbles_by_album(since=week.first_stamp(),to=week.last_stamp(),resolve_ids=False,dbconn=dbconn) diff --git a/maloja/dev/profiler.py b/maloja/dev/profiler.py index 7185431..af4e57c 100644 --- a/maloja/dev/profiler.py +++ b/maloja/dev/profiler.py @@ -15,10 +15,16 @@ 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() +if not SINGLE_CALLS: + profilers = {} + times = {} def profile(func): + + realfunc = func + while hasattr(realfunc, '__innerfunc__'): + realfunc = realfunc.__innerfunc__ + def newfunc(*args,**kwargs): clock = Clock() @@ -27,10 +33,10 @@ def profile(func): if FULL_PROFILE: benchmarkfolder = data_dir['logs']("benchmarks") os.makedirs(benchmarkfolder,exist_ok=True) - if not SINGLE_CALLS: + if SINGLE_CALLS: localprofiler = cProfile.Profile() else: - localprofiler = profiler + localprofiler = profilers.setdefault(realfunc,cProfile.Profile()) localprofiler.enable() result = func(*args,**kwargs) @@ -39,10 +45,15 @@ def profile(func): localprofiler.disable() seconds = clock.stop() - realfunc = func - while(hasattr(realfunc,'__innerfunc__')): - realfunc = realfunc.__innerfunc__ - log(f"Executed {realfunc.__name__} ({args}, {kwargs}) in {seconds:.2f}s",module="debug_performance") + + if not SINGLE_CALLS: + times.setdefault(realfunc,[]).append(seconds) + + if SINGLE_CALLS: + log(f"Executed {realfunc.__name__} ({args}, {kwargs}) in {seconds:.2f}s",module="debug_performance") + else: + log(f"Executed {realfunc.__name__} ({args}, {kwargs}) in {seconds:.2f}s (Average: { sum(times[realfunc])/len(times[realfunc]):.2f}s)",module="debug_performance") + if FULL_PROFILE: targetfilename = os.path.join(benchmarkfolder,f"{realfunc.__name__}.stats") try: