diff options
| author | Omar Roth <omarroth@hotmail.com> | 2018-02-07 22:04:47 -0600 |
|---|---|---|
| committer | Omar Roth <omarroth@hotmail.com> | 2018-02-07 22:04:47 -0600 |
| commit | 5159ec0f6e2a9f6f1b2fabdd3066b0ea3ce9c17d (patch) | |
| tree | 91d28e866ad040da947177db1aebe4217bda0123 /src | |
| parent | a017f4cc30e456bf53b9ae48b9eaac3c5e7a60d2 (diff) | |
| download | invidious-5159ec0f6e2a9f6f1b2fabdd3066b0ea3ce9c17d.tar.gz invidious-5159ec0f6e2a9f6f1b2fabdd3066b0ea3ce9c17d.tar.bz2 invidious-5159ec0f6e2a9f6f1b2fabdd3066b0ea3ce9c17d.zip | |
Pull rank_videos into seperate thread
Diffstat (limited to 'src')
| -rw-r--r-- | src/invidious.cr | 40 | ||||
| -rw-r--r-- | src/views/index.ecr | 2 |
2 files changed, 26 insertions, 16 deletions
diff --git a/src/invidious.cr b/src/invidious.cr index 9eecf106..5497ad3a 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -109,26 +109,36 @@ threads.times do end end -macro templated(filename) - render "src/views/#{{{filename}}}.ecr", "src/views/layout.ecr" - end +top_videos = [] of Video -get "/" do |env| - top = rank_videos(PG_DB, 120) +spawn do + loop do + top = rank_videos(PG_DB, 120) + client = get_client(pool) - args = [] of String - 1..(top.size - 1).times { |i| args << "($#{i + 1}), " } - args << "($#{top.size}) " - args = args.join("") + args = [] of String + 1..(top.size - 1).times { |i| args << "($#{i + 1}), " } + args << "($#{top.size}) " + args = args.join("") - videos = [] of Video - PG_DB.query("SELECT * FROM videos d INNER JOIN (VALUES #{args}) v(id) USING (id)", top) do |rs| - rs.each do - video = rs.read(Video) - videos << video + PG_DB.query("SELECT * FROM videos d INNER JOIN (VALUES #{args}) v(id) USING (id)", top) do |rs| + rs.each do + video = rs.read(Video) + top_videos << video + end end + + pool << client + + sleep 5.minutes + end +end + +macro templated(filename) + render "src/views/#{{{filename}}}.ecr", "src/views/layout.ecr" end +get "/" do |env| templated "index" end @@ -259,7 +269,7 @@ get "/:path" do |env| end error 500 do |env| - "Error 500" + templated "index" end public_folder "assets" diff --git a/src/views/index.ecr b/src/views/index.ecr index 7a25c739..3b061fa1 100644 --- a/src/views/index.ecr +++ b/src/views/index.ecr @@ -2,7 +2,7 @@ <title>Invidious</title> <% end %> -<% videos.each_slice(4) do |slice| %> +<% top_videos.each_slice(4) do |slice| %> <div class="pure-g"> <% slice.each do |video| %> <% player_response = JSON.parse(video.info["player_response"]) %> |
