From e1219cbdef9514a43a32516f1d86713d676b4ab0 Mon Sep 17 00:00:00 2001 From: matthewmcgarvey Date: Wed, 5 Jan 2022 18:24:04 -0600 Subject: [PATCH 1/3] 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 # ------------------- From ba0bc72d0b05a5a03ccf3d441011cf9ec0929ba4 Mon Sep 17 00:00:00 2001 From: matthewmcgarvey Date: Wed, 5 Jan 2022 19:03:32 -0600 Subject: [PATCH 2/3] delete_by_playlist_id -> delete_by_playlist --- src/invidious/database/playlists.cr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/invidious/database/playlists.cr b/src/invidious/database/playlists.cr index 93f62d10..1d846018 100644 --- a/src/invidious/database/playlists.cr +++ b/src/invidious/database/playlists.cr @@ -23,7 +23,7 @@ module Invidious::Database::Playlists # deletes the given playlist and connected playlist videos def delete(id : String) - PlaylistVideos.delete_by_playlist_id(id) + PlaylistVideos.delete_by_playlist(id) request = <<-SQL DELETE FROM playlists * WHERE id = $1 @@ -206,7 +206,7 @@ module Invidious::Database::PlaylistVideos PG_DB.exec(request, index) end - def delete_by_playlist_id(playlist_id) + def delete_by_playlist(playlist_id : String) request = <<-SQL DELETE FROM playlist_videos * WHERE plid = $1; From 2eb7c5c0374db96e935e6e81cc2dae5112295e1c Mon Sep 17 00:00:00 2001 From: matthewmcgarvey Date: Wed, 5 Jan 2022 20:15:42 -0600 Subject: [PATCH 3/3] PR feedback --- src/invidious/database/playlists.cr | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/invidious/database/playlists.cr b/src/invidious/database/playlists.cr index 1d846018..7a5f61dc 100644 --- a/src/invidious/database/playlists.cr +++ b/src/invidious/database/playlists.cr @@ -206,13 +206,13 @@ module Invidious::Database::PlaylistVideos PG_DB.exec(request, index) end - def delete_by_playlist(playlist_id : String) + def delete_by_playlist(plid : String) request = <<-SQL DELETE FROM playlist_videos * - WHERE plid = $1; + WHERE plid = $1 SQL - PG_DB.exec(request, playlist_id) + PG_DB.exec(request, plid) end # -------------------