From ad824626c3cf2b125b99752673b238064573b5cc Mon Sep 17 00:00:00 2001 From: krateng Date: Wed, 18 Oct 2023 15:08:56 +0200 Subject: [PATCH] Fixed duplicate counting of scrobbles when including associated artists --- maloja/database/sqldb.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/maloja/database/sqldb.py b/maloja/database/sqldb.py index c22ca39..fca8ef6 100644 --- a/maloja/database/sqldb.py +++ b/maloja/database/sqldb.py @@ -783,6 +783,17 @@ def get_scrobbles_of_artist(artist,since=None,to=None,resolve_references=True,as ).order_by(sql.asc('timestamp')) result = dbconn.execute(op).all() + # remove duplicates (multiple associated artists in the song, e.g. Irene & Seulgi being both counted as Red Velvet) + # distinct on doesn't seem to exist in sqlite + seen = set() + filtered_result = [] + for row in result: + if row.timestamp not in seen: + filtered_result.append(row) + seen.add(row.timestamp) + result = filtered_result + + if resolve_references: result = scrobbles_db_to_dict(result,dbconn=dbconn) #result = [scrobble_db_to_dict(row,resolve_references=resolve_references) for row in result]