summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOmar Roth <omarroth@protonmail.com>2019-06-06 21:33:30 -0500
committerOmar Roth <omarroth@protonmail.com>2019-06-06 21:33:30 -0500
commit317d8703ca506394af1adf5f72b1c66c83bb704b (patch)
treed00be2dba3f378c688bef8bece76291e9ea01504 /src
parentfda619f704a442970157407c8446341ccdb84977 (diff)
downloadinvidious-317d8703ca506394af1adf5f72b1c66c83bb704b.tar.gz
invidious-317d8703ca506394af1adf5f72b1c66c83bb704b.tar.bz2
invidious-317d8703ca506394af1adf5f72b1c66c83bb704b.zip
Optimize query for pulling popular videos
Diffstat (limited to 'src')
-rw-r--r--src/invidious/helpers/jobs.cr11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/invidious/helpers/jobs.cr b/src/invidious/helpers/jobs.cr
index 63f7c16f..ee468d1a 100644
--- a/src/invidious/helpers/jobs.cr
+++ b/src/invidious/helpers/jobs.cr
@@ -200,13 +200,10 @@ end
def 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 }.reverse
yield videos
sleep 1.minute