diff --git a/maloja/database/__init__.py b/maloja/database/__init__.py index 2d4f3dd..4a2851a 100644 --- a/maloja/database/__init__.py +++ b/maloja/database/__init__.py @@ -139,7 +139,16 @@ def get_scrobbles(dbconn=None,**keys): @waitfordb def get_scrobbles_num(dbconn=None,**keys): - return len(get_scrobbles(dbconn=dbconn,**keys)) + (since,to) = keys.get('timerange').timestamps() + if 'artist' in keys: + result = len(sqldb.get_scrobbles_of_artist(artist=keys['artist'],since=since,to=to,resolve_references=False,dbconn=dbconn)) + elif 'track' in keys: + result = len(sqldb.get_scrobbles_of_track(track=keys['track'],since=since,to=to,resolve_references=False,dbconn=dbconn)) + else: + result = sqldb.get_scrobbles_num(since=since,to=to,dbconn=dbconn) + return result + + @waitfordb def get_tracks(dbconn=None,**keys): diff --git a/maloja/database/sqldb.py b/maloja/database/sqldb.py index fc4a531..2f022e4 100644 --- a/maloja/database/sqldb.py +++ b/maloja/database/sqldb.py @@ -283,7 +283,7 @@ def get_artist_id(artistname,dbconn=None): @cached_wrapper @connection_provider -def get_scrobbles_of_artist(artist,since=None,to=None,dbconn=None): +def get_scrobbles_of_artist(artist,since=None,to=None,resolve_references=True,dbconn=None): if since is None: since=0 if to is None: to=now() @@ -299,13 +299,14 @@ def get_scrobbles_of_artist(artist,since=None,to=None,dbconn=None): ).order_by(sql.asc('timestamp')) result = dbconn.execute(op).all() - result = scrobbles_db_to_dict(result) + if resolve_references: + result = scrobbles_db_to_dict(result) #result = [scrobble_db_to_dict(row,resolve_references=resolve_references) for row in result] return result @cached_wrapper @connection_provider -def get_scrobbles_of_track(track,since=None,to=None,dbconn=None): +def get_scrobbles_of_track(track,since=None,to=None,resolve_references=True,dbconn=None): if since is None: since=0 if to is None: to=now() @@ -319,7 +320,8 @@ def get_scrobbles_of_track(track,since=None,to=None,dbconn=None): ).order_by(sql.asc('timestamp')) result = dbconn.execute(op).all() - result = scrobbles_db_to_dict(result) + if resolve_references: + result = scrobbles_db_to_dict(result) #result = [scrobble_db_to_dict(row) for row in result] return result @@ -336,10 +338,28 @@ def get_scrobbles(since=None,to=None,resolve_references=True,dbconn=None): ).order_by(sql.asc('timestamp')) result = dbconn.execute(op).all() - result = scrobbles_db_to_dict(result) + if resolve_references: + result = scrobbles_db_to_dict(result) #result = [scrobble_db_to_dict(row,resolve_references=resolve_references) for i,row in enumerate(result) if i=since, + ) + result = dbconn.execute(op).all() + + return result[0][0] + @cached_wrapper @connection_provider def get_artists_of_track(track_id,resolve_references=True,dbconn=None):