diff --git a/maloja/apis/native_v1.py b/maloja/apis/native_v1.py index 0e972b4..12889ae 100644 --- a/maloja/apis/native_v1.py +++ b/maloja/apis/native_v1.py @@ -403,4 +403,4 @@ def get_export(**keys): @api.post("delete_scrobble") @authenticated_api def delete_scrobble(timestamp): - pass + database.remove_scrobble(timestamp) diff --git a/maloja/database/__init__.py b/maloja/database/__init__.py index 267a4a3..e01956b 100644 --- a/maloja/database/__init__.py +++ b/maloja/database/__init__.py @@ -133,6 +133,11 @@ def incoming_scrobble(rawscrobble,fix=True,client=None,api=None,dbconn=None): +@waitfordb +def remove_scrobble(timestamp): + result = sqldb.delete_scrobble(timestamp) + dbcache.invalidate_caches(timestamp) + diff --git a/maloja/database/sqldb.py b/maloja/database/sqldb.py index c564b3c..3776d2f 100644 --- a/maloja/database/sqldb.py +++ b/maloja/database/sqldb.py @@ -266,6 +266,16 @@ def add_scrobbles(scrobbleslist,dbconn=None): if errors > 0: log(f"{errors} Scrobbles have not been written to database!",color='red') return success,errors +@connection_provider +def delete_scrobble(scrobble_id,dbconn=None): + + with SCROBBLE_LOCK: + + op = DB['scrobbles'].delete().where( + DB['scrobbles'].c.timestamp == scrobble_id + ) + + dbconn.execute(op) ### these will 'get' the ID of an entity, creating it if necessary diff --git a/maloja/web/static/js/edit.js b/maloja/web/static/js/edit.js index c44afc0..0a415ba 100644 --- a/maloja/web/static/js/edit.js +++ b/maloja/web/static/js/edit.js @@ -7,4 +7,6 @@ function toggleDeleteConfirm(element) { function deleteScrobble(id,element) { element.parentElement.parentElement.parentElement.classList.add('removed'); + neo.xhttpreq("/apis/mlj_1/delete_scrobble",data={'timestamp':id},method="POST",callback=(()=>null),json=true); + }