mirror of
https://github.com/iv-org/invidious
synced 2024-11-09 01:10:27 +00:00
Add back in refreshing of channels every 2 days
This commit is contained in:
parent
a82d21ff78
commit
e92b3779ad
@ -152,12 +152,14 @@ def get_batch_channels(channels)
|
||||
return final
|
||||
end
|
||||
|
||||
def get_channel(id)
|
||||
def get_channel(id) : InvidiousChannel
|
||||
channel = Invidious::Database::Channels.select(id)
|
||||
return channel if channel
|
||||
|
||||
channel = fetch_channel(id, pull_all_videos: false)
|
||||
Invidious::Database::Channels.insert(channel)
|
||||
if channel.nil? || (Time.utc - channel.updated) > 2.days
|
||||
channel = fetch_channel(id, pull_all_videos: false)
|
||||
Invidious::Database::Channels.insert(channel, update_on_conflict: true)
|
||||
end
|
||||
|
||||
return channel
|
||||
end
|
||||
|
||||
|
@ -10,7 +10,7 @@ module Invidious::Database::Channels
|
||||
# Insert / delete
|
||||
# -------------------
|
||||
|
||||
def insert(channel : InvidiousChannel)
|
||||
def insert(channel : InvidiousChannel, update_on_conflict : Bool = false)
|
||||
channel_array = channel.to_a
|
||||
|
||||
request = <<-SQL
|
||||
@ -18,6 +18,13 @@ module Invidious::Database::Channels
|
||||
VALUES (#{arg_array(channel_array)})
|
||||
SQL
|
||||
|
||||
if update_on_conflict
|
||||
request += <<-SQL
|
||||
ON CONFLICT (id) DO UPDATE
|
||||
SET author = $2, updated = $3
|
||||
SQL
|
||||
end
|
||||
|
||||
PG_DB.exec(request, args: channel_array)
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user