diff options
| author | Omar Roth <omarroth@hotmail.com> | 2018-07-17 09:20:07 -0500 |
|---|---|---|
| committer | Omar Roth <omarroth@hotmail.com> | 2018-07-17 09:20:07 -0500 |
| commit | e1ec1b68378203651e9e4b649009b2856a8aecad (patch) | |
| tree | 2064460de887ad0ac0929a1def33de52c862eb78 | |
| parent | 7119395045fa92462bee43c778032c9d03015f31 (diff) | |
| download | invidious-e1ec1b68378203651e9e4b649009b2856a8aecad.tar.gz invidious-e1ec1b68378203651e9e4b649009b2856a8aecad.tar.bz2 invidious-e1ec1b68378203651e9e4b649009b2856a8aecad.zip | |
Use smarter query for updating channels
| -rw-r--r-- | src/invidious/helpers.cr | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/invidious/helpers.cr b/src/invidious/helpers.cr index 94281471..692c1d29 100644 --- a/src/invidious/helpers.cr +++ b/src/invidious/helpers.cr @@ -685,15 +685,19 @@ def fetch_channel(ucid, client, db, pull_all_videos = true) page += 1 end - db.exec("DELETE FROM channel_videos * WHERE ucid = $1", ucid) + video_ids = [] of String videos.each do |video| db.exec("UPDATE users SET notifications = notifications || $1 \ WHERE updated < $2 AND $3 = ANY(subscriptions) AND $1 <> ALL(notifications)", video.id, video.published, ucid) + video_ids << video.id video_array = video.to_a args = arg_array(video_array) db.exec("INSERT INTO channel_videos VALUES (#{args}) ON CONFLICT (id) DO NOTHING", video_array) end + + # When a video is deleted from a channel, we find and remove it here + db.exec("DELETE FROM channel_videos * WHERE NOT id = ANY ('{#{video_ids.map { |a| %("#{a}") }.join(",")}}') AND ucid = $1", ucid) end channel = InvidiousChannel.new(ucid, author, Time.now) |
