mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2022-03-16.git
synced 2024-08-15 00:53:18 +00:00
Provide rough draft of better project organization
This commit is contained in:
parent
1978c3d3bd
commit
85c212aee3
9 changed files with 115 additions and 43 deletions
3
src/invidious/jobs/base_job.cr
Normal file
3
src/invidious/jobs/base_job.cr
Normal file
|
@ -0,0 +1,3 @@
|
|||
abstract class Invidious::Jobs::BaseJob
|
||||
abstract def begin
|
||||
end
|
27
src/invidious/jobs/pull_popular_videos_job.cr
Normal file
27
src/invidious/jobs/pull_popular_videos_job.cr
Normal file
|
@ -0,0 +1,27 @@
|
|||
class Invidious::Jobs::PullPopularVideosJob < Invidious::Jobs::BaseJob
|
||||
QUERY = <<-SQL
|
||||
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
|
||||
SQL
|
||||
POPULAR_VIDEOS = Atomic.new([] of ChannelVideo)
|
||||
private getter db : DB::Database
|
||||
|
||||
def initialize(@db)
|
||||
end
|
||||
|
||||
def begin
|
||||
loop do
|
||||
videos = db.query_all(QUERY, as: ChannelVideo)
|
||||
.sort_by(&.published)
|
||||
.reverse
|
||||
|
||||
POPULAR_VIDEOS.set(videos)
|
||||
|
||||
sleep 1.minute
|
||||
Fiber.yield
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue