diff --git a/maloja/database/__init__.py b/maloja/database/__init__.py index 541a005..533af03 100644 --- a/maloja/database/__init__.py +++ b/maloja/database/__init__.py @@ -584,7 +584,7 @@ def db_query_full(artist=None,artists=None,title=None,track=None,timerange=None, # Queries that... well... aggregate -def db_aggregate_full(by=None,within=None,timerange=None,artist=None): +def db_aggregate_full(by=None,timerange=None,artist=None): if not dbstatus['healthy']: raise DatabaseNotBuilt() (since, to) = time_stamps(range=timerange) @@ -592,15 +592,20 @@ def db_aggregate_full(by=None,within=None,timerange=None,artist=None): if (by=="ARTIST"): + trackcharts = {} charts = {} - scrobbles = sqldb.get_scrobbles(since=since,to=to) - for s in scrobbles_in_range(since,to): - artists = TRACKS[s[0]][0] - for a in coa.getCreditedList(artists): - # this either creates the new entry or increments the existing one - charts[a] = charts.setdefault(a,0) + 1 + scrobbles = sqldb.get_scrobbles(since=since,to=to,resolve_references=False) - ls = [{"artist":get_artist_dict(ARTISTS[a]),"scrobbles":charts[a],"counting":[arti for arti in coa.getAllAssociated(ARTISTS[a]) if arti in ARTISTS]} for a in charts] + for s in scrobbles: + trackcharts[s['track']] = trackcharts.setdefault(s['track'],0) + 1 + + for t in trackcharts: + artists = sqldb.get_artists_of_track(t,resolve_references=False) + for a in coa.getCreditedList(artists): + charts[a] = charts.setdefault(a,0) + trackcharts[t] + + + ls = [{"artist":sqldb.get_artist(a),"scrobbles":charts[a],"counting":[]} for a in charts] ls.sort(key=lambda k:k["scrobbles"],reverse=True) # add ranks for rnk in range(len(ls)): diff --git a/maloja/database/cache.py b/maloja/database/cache.py index 90a672b..a4c2ee3 100644 --- a/maloja/database/cache.py +++ b/maloja/database/cache.py @@ -15,7 +15,7 @@ from ..globalconf import malojaconfig from .. import utilities from .. import database as dbmain -if malojaconfig["USE_DB_CACHE"]: +if False: def db_query(**kwargs): return db_query_cached(**kwargs) def db_aggregate(**kwargs): diff --git a/maloja/database/sqldb.py b/maloja/database/sqldb.py index 59d6ef4..104ef2b 100644 --- a/maloja/database/sqldb.py +++ b/maloja/database/sqldb.py @@ -291,14 +291,14 @@ def get_artist(id): artistinfo = result[0] return artist_db_to_dict(artistinfo) -def get_artists_of_track(track_id): +def get_artists_of_track(track_id,resolve_references=True): with engine.begin() as conn: op = DB['trackartists'].select().where( DB['trackartists'].c.track_id==track_id ) result = conn.execute(op).all() - artists = [get_artist(row.artist_id) for row in result] + artists = [get_artist(row.artist_id) if resolve_references else row.artist_id for row in result] return artists