Pull rank_videos into seperate thread

このコミットが含まれているのは:
Omar Roth 2018-02-07 22:04:47 -06:00
コミット 5159ec0f6e
2個のファイルの変更27行の追加17行の削除

ファイルの表示

@ -109,26 +109,36 @@ threads.times do
end
end
top_videos = [] of Video
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("")
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|
top = rank_videos(PG_DB, 120)
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
end
end
templated "index"
end
@ -259,7 +269,7 @@ get "/:path" do |env|
end
error 500 do |env|
"Error 500"
templated "index"
end
public_folder "assets"

ファイルの表示

@ -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"]) %>