Add refresh for top videos
This commit is contained in:
parent
36b184d1fb
commit
2be57276a2
@ -183,8 +183,8 @@ def get_video(id, client, db, refresh = true)
|
|||||||
|
|
||||||
# If record was last updated over an hour ago, refresh (expire param in response lasts for 6 hours)
|
# If record was last updated over an hour ago, refresh (expire param in response lasts for 6 hours)
|
||||||
if refresh && Time.now - video.updated > 1.hours
|
if refresh && Time.now - video.updated > 1.hours
|
||||||
video = fetch_video(id, client)
|
|
||||||
db.exec("DELETE FROM videos * WHERE id = $1", id)
|
db.exec("DELETE FROM videos * WHERE id = $1", id)
|
||||||
|
video = fetch_video(id, client)
|
||||||
args = arg_array(video.to_a)
|
args = arg_array(video.to_a)
|
||||||
db.exec("INSERT INTO videos VALUES (#{args})", video.to_a)
|
db.exec("INSERT INTO videos VALUES (#{args})", video.to_a)
|
||||||
end
|
end
|
||||||
|
@ -145,11 +145,10 @@ spawn do
|
|||||||
|
|
||||||
videos = [] of Video
|
videos = [] of Video
|
||||||
|
|
||||||
PG_DB.query("SELECT * FROM videos d INNER JOIN (VALUES #{args}) v(id) USING (id)", top) do |rs|
|
top.each do |id|
|
||||||
rs.each do
|
client = get_client(youtube_pool)
|
||||||
video = rs.read(Video)
|
videos << get_video(id, client, PG_DB)
|
||||||
videos << video
|
youtube_pool << client
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
top_videos = videos
|
top_videos = videos
|
||||||
|
Loading…
Reference in New Issue
Block a user