From e1219cbdef9514a43a32516f1d86713d676b4ab0 Mon Sep 17 00:00:00 2001 From: matthewmcgarvey Date: Wed, 5 Jan 2022 18:24:04 -0600 Subject: [PATCH] Fix playlist deletion --- src/invidious/database/playlists.cr | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/invidious/database/playlists.cr b/src/invidious/database/playlists.cr index 950d5f4b..93f62d10 100644 --- a/src/invidious/database/playlists.cr +++ b/src/invidious/database/playlists.cr @@ -21,13 +21,12 @@ module Invidious::Database::Playlists PG_DB.exec(request, args: playlist_array) end - # this function is a bit special: it will also remove all videos - # related to the given playlist ID in the "playlist_videos" table, - # in addition to deleting said ID from "playlists". + # deletes the given playlist and connected playlist videos def delete(id : String) + PlaylistVideos.delete_by_playlist_id(id) request = <<-SQL - DELETE FROM playlist_videos * WHERE plid = $1; - DELETE FROM playlists * WHERE id = $1 + DELETE FROM playlists * + WHERE id = $1 SQL PG_DB.exec(request, id) @@ -207,6 +206,15 @@ module Invidious::Database::PlaylistVideos PG_DB.exec(request, index) end + def delete_by_playlist_id(playlist_id) + request = <<-SQL + DELETE FROM playlist_videos * + WHERE plid = $1; + SQL + + PG_DB.exec(request, playlist_id) + end + # ------------------- # Salect # -------------------