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) return PG_DB.query_all(request, as: InvidiousChannel)
end end
def select_all : Array(InvidiousChannel)
request = <<-SQL
SELECT * FROM channels
SQL
return PG_DB.query_all(rqeuest, as: InvidiousChannel)
end
end end
# #

View File

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