Invidious is an alternative front-end to YouTube
Optimize query for pulling popular videos
Omar Roth317d8703ca50
diff --git a/src/invidious/helpers/jobs.cr b/src/invidious/helpers/jobs.crindex 63f7c16f..ee468d1a 100644--- a/src/invidious/helpers/jobs.cr+++ b/src/invidious/helpers/jobs.cr@@ -200,13 +200,10 @@ enddef pull_popular_videos(db)loop do- subscriptions = db.query_all("SELECT channel FROM \- (SELECT UNNEST(subscriptions) AS channel FROM users) AS d \- GROUP BY channel ORDER BY COUNT(channel) DESC LIMIT 40", as: String)-- videos = db.query_all("SELECT DISTINCT ON (ucid) * FROM \- channel_videos WHERE ucid IN (#{arg_array(subscriptions)}) \- ORDER BY ucid, published DESC", subscriptions, as: ChannelVideo).sort_by { |video| video.published }.reverse+ videos = db.query_all("SELECT DISTINCT ON (ucid) * FROM channel_videos WHERE ucid IN \+ (SELECT channel FROM (SELECT UNNEST(subscriptions) AS channel FROM users) AS d \+ GROUP BY channel ORDER BY COUNT(channel) DESC LIMIT 40) \+ ORDER BY ucid, published DESC", as: ChannelVideo).sort_by { |video| video.published }.reverseyield videossleep 1.minute