From 8445d3ae120c52eba531183caa1fa63d5701f322 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Sun, 19 Feb 2023 19:01:28 -0500 Subject: [PATCH 1/3] Fix watch history order --- src/invidious/database/users.cr | 1 + src/invidious/routes/watch.cr | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/invidious/database/users.cr b/src/invidious/database/users.cr index 0a4a4fd8..f8422874 100644 --- a/src/invidious/database/users.cr +++ b/src/invidious/database/users.cr @@ -50,6 +50,7 @@ module Invidious::Database::Users end def mark_watched(user : User, vid : String) + mark_unwatched(user, vid) request = <<-SQL UPDATE users SET watched = array_append(watched, $1) diff --git a/src/invidious/routes/watch.cr b/src/invidious/routes/watch.cr index 5d3845c3..813cb0f4 100644 --- a/src/invidious/routes/watch.cr +++ b/src/invidious/routes/watch.cr @@ -76,7 +76,7 @@ module Invidious::Routes::Watch end env.params.query.delete_all("iv_load_policy") - if watched && preferences.watch_history && !watched.includes? id + if watched && preferences.watch_history Invidious::Database::Users.mark_watched(user.as(User), id) end @@ -259,9 +259,7 @@ module Invidious::Routes::Watch case action when "action_mark_watched" - if !user.watched.includes? id - Invidious::Database::Users.mark_watched(user, id) - end + Invidious::Database::Users.mark_watched(user, id) when "action_mark_unwatched" Invidious::Database::Users.mark_unwatched(user, id) else From 20289a4d014d36c9a7bd50d8b1549bf36f78eb59 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Mon, 20 Feb 2023 14:56:38 -0500 Subject: [PATCH 2/3] Fix order for import --- src/invidious/user/imports.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/invidious/user/imports.cr b/src/invidious/user/imports.cr index 20ae0d47..aa947456 100644 --- a/src/invidious/user/imports.cr +++ b/src/invidious/user/imports.cr @@ -48,7 +48,7 @@ struct Invidious::User if data["watch_history"]? user.watched += data["watch_history"].as_a.map(&.as_s) - user.watched.uniq! + user.watched.reverse!.uniq!.reverse! Invidious::Database::Users.update_watch_history(user) end From 025e7555420a88757aa8709419e8f09ba654854d Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Sat, 4 Mar 2023 19:14:28 -0500 Subject: [PATCH 3/3] Use single db call --- src/invidious/database/users.cr | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/invidious/database/users.cr b/src/invidious/database/users.cr index f8422874..d54e6a76 100644 --- a/src/invidious/database/users.cr +++ b/src/invidious/database/users.cr @@ -50,10 +50,9 @@ module Invidious::Database::Users end def mark_watched(user : User, vid : String) - mark_unwatched(user, vid) request = <<-SQL UPDATE users - SET watched = array_append(watched, $1) + SET watched = array_append(array_remove(watched, $1), $1) WHERE email = $2 SQL