|
|
@ -109,26 +109,36 @@ threads.times do
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
macro templated(filename)
|
|
|
|
top_videos = [] of Video
|
|
|
|
render "src/views/#{{{filename}}}.ecr", "src/views/layout.ecr"
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get "/" do |env|
|
|
|
|
spawn do
|
|
|
|
top = rank_videos(PG_DB, 120)
|
|
|
|
loop do
|
|
|
|
|
|
|
|
top = rank_videos(PG_DB, 120)
|
|
|
|
|
|
|
|
client = get_client(pool)
|
|
|
|
|
|
|
|
|
|
|
|
args = [] of String
|
|
|
|
args = [] of String
|
|
|
|
1..(top.size - 1).times { |i| args << "($#{i + 1}), " }
|
|
|
|
1..(top.size - 1).times { |i| args << "($#{i + 1}), " }
|
|
|
|
args << "($#{top.size}) "
|
|
|
|
args << "($#{top.size}) "
|
|
|
|
args = args.join("")
|
|
|
|
args = args.join("")
|
|
|
|
|
|
|
|
|
|
|
|
videos = [] of Video
|
|
|
|
PG_DB.query("SELECT * FROM videos d INNER JOIN (VALUES #{args}) v(id) USING (id)", top) do |rs|
|
|
|
|
PG_DB.query("SELECT * FROM videos d INNER JOIN (VALUES #{args}) v(id) USING (id)", top) do |rs|
|
|
|
|
rs.each do
|
|
|
|
rs.each do
|
|
|
|
video = rs.read(Video)
|
|
|
|
video = rs.read(Video)
|
|
|
|
top_videos << video
|
|
|
|
videos << video
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pool << client
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sleep 5.minutes
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
macro templated(filename)
|
|
|
|
|
|
|
|
render "src/views/#{{{filename}}}.ecr", "src/views/layout.ecr"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get "/" do |env|
|
|
|
|
templated "index"
|
|
|
|
templated "index"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -259,7 +269,7 @@ get "/:path" do |env|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
error 500 do |env|
|
|
|
|
error 500 do |env|
|
|
|
|
"Error 500"
|
|
|
|
templated "index"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
public_folder "assets"
|
|
|
|
public_folder "assets"
|
|
|
|