From 2be57276a27308e9e0619729905273eb285770b7 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Fri, 16 Mar 2018 23:01:35 -0500 Subject: [PATCH] Add refresh for top videos --- src/helpers.cr | 2 +- src/invidious.cr | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/helpers.cr b/src/helpers.cr index 318936037..6a7077344 100644 --- a/src/helpers.cr +++ b/src/helpers.cr @@ -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 refresh && Time.now - video.updated > 1.hours - video = fetch_video(id, client) db.exec("DELETE FROM videos * WHERE id = $1", id) + video = fetch_video(id, client) args = arg_array(video.to_a) db.exec("INSERT INTO videos VALUES (#{args})", video.to_a) end diff --git a/src/invidious.cr b/src/invidious.cr index 617915c22..41544f9eb 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -145,11 +145,10 @@ spawn do 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 + top.each do |id| + client = get_client(youtube_pool) + videos << get_video(id, client, PG_DB) + youtube_pool << client end top_videos = videos