mirror of https://github.com/iv-org/invidious.git
Add channel refresh
This commit is contained in:
parent
252f1c0af3
commit
edfe1eefe8
|
@ -489,11 +489,12 @@ def get_channel(id, client, db)
|
||||||
if db.query_one?("SELECT EXISTS (SELECT true FROM channels WHERE id = $1)", id, as: Bool)
|
if db.query_one?("SELECT EXISTS (SELECT true FROM channels WHERE id = $1)", id, as: Bool)
|
||||||
channel = db.query_one("SELECT * FROM channels WHERE id = $1", id, as: InvidiousChannel)
|
channel = db.query_one("SELECT * FROM channels WHERE id = $1", id, as: InvidiousChannel)
|
||||||
|
|
||||||
if Time.now - channel.updated > 1.hours
|
if Time.now - channel.updated > 1.minutes
|
||||||
db.exec("DELETE FROM channels * WHERE id = $1", id)
|
|
||||||
channel = fetch_channel(id, client)
|
channel = fetch_channel(id, client)
|
||||||
args = arg_array(channel.to_a)
|
channel_array = channel.to_a[1..-1]
|
||||||
db.exec("INSERT INTO channels VALUES (#{args})", channel.to_a)
|
args = arg_array(channel_array)
|
||||||
|
|
||||||
|
db.exec("UPDATE channels SET (rss,updated,author) = (#{args}) WHERE id = '#{channel.id}'", channel_array)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
channel = fetch_channel(id, client)
|
channel = fetch_channel(id, client)
|
||||||
|
|
|
@ -27,6 +27,7 @@ CONFIG = Config.from_yaml(File.read("config/config.yml"))
|
||||||
|
|
||||||
pool_size = CONFIG.pool_size
|
pool_size = CONFIG.pool_size
|
||||||
threads = CONFIG.threads
|
threads = CONFIG.threads
|
||||||
|
channel_threads = 10
|
||||||
|
|
||||||
Kemal.config.extra_options do |parser|
|
Kemal.config.extra_options do |parser|
|
||||||
parser.banner = "Usage: invidious [arguments]"
|
parser.banner = "Usage: invidious [arguments]"
|
||||||
|
@ -122,6 +123,24 @@ threads.times do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
channel_threads.times do |i|
|
||||||
|
spawn do
|
||||||
|
loop do
|
||||||
|
query = "SELECT id FROM channels ORDER BY updated \
|
||||||
|
LIMIT (SELECT count(*)/#{channel_threads} FROM channels) \
|
||||||
|
OFFSET (SELECT count(*)*#{i}/#{channel_threads} FROM channels)"
|
||||||
|
PG_DB.query(query) do |rs|
|
||||||
|
rs.each do
|
||||||
|
client = get_client(youtube_pool)
|
||||||
|
id = rs.read(String)
|
||||||
|
channel = get_channel(id, client, PG_DB)
|
||||||
|
youtube_pool << client
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
top_videos = [] of Video
|
top_videos = [] of Video
|
||||||
|
|
||||||
spawn do
|
spawn do
|
||||||
|
|
Loading…
Reference in New Issue