mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2022-04-11.git
synced 2024-08-15 00:43:26 +00:00
Use smarter query for updating channels
This commit is contained in:
parent
7119395045
commit
e1ec1b6837
1 changed files with 5 additions and 1 deletions
|
@ -685,15 +685,19 @@ def fetch_channel(ucid, client, db, pull_all_videos = true)
|
||||||
page += 1
|
page += 1
|
||||||
end
|
end
|
||||||
|
|
||||||
db.exec("DELETE FROM channel_videos * WHERE ucid = $1", ucid)
|
video_ids = [] of String
|
||||||
videos.each do |video|
|
videos.each do |video|
|
||||||
db.exec("UPDATE users SET notifications = notifications || $1 \
|
db.exec("UPDATE users SET notifications = notifications || $1 \
|
||||||
WHERE updated < $2 AND $3 = ANY(subscriptions) AND $1 <> ALL(notifications)", video.id, video.published, ucid)
|
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
|
video_array = video.to_a
|
||||||
args = arg_array(video_array)
|
args = arg_array(video_array)
|
||||||
db.exec("INSERT INTO channel_videos VALUES (#{args}) ON CONFLICT (id) DO NOTHING", video_array)
|
db.exec("INSERT INTO channel_videos VALUES (#{args}) ON CONFLICT (id) DO NOTHING", video_array)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
channel = InvidiousChannel.new(ucid, author, Time.now)
|
channel = InvidiousChannel.new(ucid, author, Time.now)
|
||||||
|
|
Loading…
Reference in a new issue