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
|
return final
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_channel(id)
|
def get_channel(id) : InvidiousChannel
|
||||||
channel = Invidious::Database::Channels.select(id)
|
channel = Invidious::Database::Channels.select(id)
|
||||||
return channel if channel
|
|
||||||
|
|
||||||
channel = fetch_channel(id, pull_all_videos: false)
|
if channel.nil? || (Time.utc - channel.updated) > 2.days
|
||||||
Invidious::Database::Channels.insert(channel)
|
channel = fetch_channel(id, pull_all_videos: false)
|
||||||
|
Invidious::Database::Channels.insert(channel, update_on_conflict: true)
|
||||||
|
end
|
||||||
|
|
||||||
return channel
|
return channel
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ module Invidious::Database::Channels
|
||||||
# Insert / delete
|
# Insert / delete
|
||||||
# -------------------
|
# -------------------
|
||||||
|
|
||||||
def insert(channel : InvidiousChannel)
|
def insert(channel : InvidiousChannel, update_on_conflict : Bool = false)
|
||||||
channel_array = channel.to_a
|
channel_array = channel.to_a
|
||||||
|
|
||||||
request = <<-SQL
|
request = <<-SQL
|
||||||
|
@ -18,6 +18,13 @@ module Invidious::Database::Channels
|
||||||
VALUES (#{arg_array(channel_array)})
|
VALUES (#{arg_array(channel_array)})
|
||||||
SQL
|
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)
|
PG_DB.exec(request, args: channel_array)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue