From 1caf6a32985338cccd4f189f924d60a3d4aa6cf8 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Fri, 28 Feb 2020 13:13:48 -0500 Subject: [PATCH] Fix deadlock when updating notifications --- src/invidious.cr | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index ea8cbcd2..0c80f8e0 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -3402,8 +3402,8 @@ post "/feed/webhook/:token" do |env| views: video.views, ) - emails = PG_DB.query_all("UPDATE users SET notifications = array_append(notifications, $1) \ - WHERE updated < $2 AND $3 = ANY(subscriptions) AND $1 <> ALL(notifications) RETURNING email", + PG_DB.query_all("UPDATE users SET feed_needs_update = true, notifications = array_append(notifications, $1) \ + WHERE updated < $2 AND $3 = ANY(subscriptions) AND $1 <> ALL(notifications)", video.id, video.published, video.ucid, as: String) video_array = video.to_a @@ -3413,15 +3413,6 @@ post "/feed/webhook/:token" do |env| ON CONFLICT (id) DO UPDATE SET title = $2, published = $3, \ updated = $4, ucid = $5, author = $6, length_seconds = $7, \ live_now = $8, premiere_timestamp = $9, views = $10", args: video_array) - - # Update all users affected by insert - if emails.empty? - values = "'{}'" - else - values = "VALUES #{emails.map { |email| %((E'#{email.gsub({'\'' => "\\'", '\\' => "\\\\"})}')) }.join(",")}" - end - - PG_DB.exec("UPDATE users SET feed_needs_update = true WHERE email = ANY(#{values})") end end