Add select_all for channels and use in refresh job

This commit is contained in:
matthewmcgarvey 2022-01-22 09:53:24 -06:00
parent 8b0ed8b110
commit 7e25ad5e4e
2 changed files with 39 additions and 34 deletions

View File

@ -76,6 +76,14 @@ module Invidious::Database::Channels
return PG_DB.query_all(request, as: InvidiousChannel)
end
def select_all : Array(InvidiousChannel)
request = <<-SQL
SELECT * FROM channels
SQL
return PG_DB.query_all(rqeuest, as: InvidiousChannel)
end
end
#

View File

@ -13,10 +13,8 @@ class Invidious::Jobs::RefreshChannelsJob < Invidious::Jobs::BaseJob
loop do
LOGGER.debug("RefreshChannelsJob: Refreshing all channels")
PG_DB.query("SELECT id FROM channels ORDER BY updated") do |rs|
rs.each do
id = rs.read(String)
Invidious::Database::Channels.select_all.each do |channel|
id = channel.id
if active_fibers >= lim_fibers
LOGGER.trace("RefreshChannelsJob: Fiber limit reached, waiting...")
if active_channel.receive
@ -56,7 +54,6 @@ class Invidious::Jobs::RefreshChannelsJob < Invidious::Jobs::BaseJob
end
end
end
end
# TODO: make this configurable
LOGGER.debug("RefreshChannelsJob: Done, sleeping for thirty minutes")