mirror of
https://github.com/iv-org/invidious.git
synced 2024-10-01 01:25:56 -04:00
Optimize query for pulling popular videos
This commit is contained in:
parent
fda619f704
commit
317d8703ca
@ -200,13 +200,10 @@ end
|
|||||||
|
|
||||||
def pull_popular_videos(db)
|
def pull_popular_videos(db)
|
||||||
loop do
|
loop do
|
||||||
subscriptions = db.query_all("SELECT channel FROM \
|
videos = db.query_all("SELECT DISTINCT ON (ucid) * FROM channel_videos WHERE ucid IN \
|
||||||
(SELECT UNNEST(subscriptions) AS channel FROM users) AS d \
|
(SELECT channel FROM (SELECT UNNEST(subscriptions) AS channel FROM users) AS d \
|
||||||
GROUP BY channel ORDER BY COUNT(channel) DESC LIMIT 40", as: String)
|
GROUP BY channel ORDER BY COUNT(channel) DESC LIMIT 40) \
|
||||||
|
ORDER BY ucid, published DESC", as: ChannelVideo).sort_by { |video| video.published }.reverse
|
||||||
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
|
|
||||||
|
|
||||||
yield videos
|
yield videos
|
||||||
sleep 1.minute
|
sleep 1.minute
|
||||||
|
Loading…
Reference in New Issue
Block a user