From 4082f9e215f514b2e33718d0da3c114e8b707030 Mon Sep 17 00:00:00 2001 From: whatdoineed2do/Ray Date: Sat, 28 Nov 2020 08:27:52 +0100 Subject: [PATCH] [library] Add function to delete playlist by id that directly invalidates the REST API client caches --- src/httpd_jsonapi.c | 2 +- src/library.c | 19 +++++++++++++++++++ src/library.h | 3 +++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/httpd_jsonapi.c b/src/httpd_jsonapi.c index 201363c7..8f7e12c7 100644 --- a/src/httpd_jsonapi.c +++ b/src/httpd_jsonapi.c @@ -3581,7 +3581,7 @@ jsonapi_reply_library_playlist_delete(struct httpd_request *hreq) return HTTP_BADREQUEST; } - db_pl_delete(pl_id); + library_playlist_remove_byid(pl_id); return HTTP_NOCONTENT; } diff --git a/src/library.c b/src/library.c index 1db8f52f..20c1c215 100644 --- a/src/library.c +++ b/src/library.c @@ -742,6 +742,25 @@ library_playlist_remove(char *virtual_path) return commands_exec_sync(cmdbase, playlist_remove, NULL, virtual_path); } +int +library_playlist_remove_byid(int pl_id) +{ + if (scanning) + { + DPRINTF(E_INFO, L_LIB, "Scan already running, ignoring request to remove playlist '%d'\n", pl_id); + return -1; + } + + db_pl_delete(pl_id); + + if (handle_deferred_update_notifications()) + listener_notify(LISTENER_UPDATE | LISTENER_DATABASE); + else + listener_notify(LISTENER_UPDATE); + + return 0; +} + int library_queue_save(char *path) { diff --git a/src/library.h b/src/library.h index 0c0a661a..90b79087 100644 --- a/src/library.h +++ b/src/library.h @@ -189,6 +189,9 @@ library_playlist_item_add(const char *vp_playlist, const char *vp_item); int library_playlist_remove(char *virtual_path); +int +library_playlist_remove_byid(int plid); + int library_queue_save(char *path);