Don't change id for video conflict

This commit is contained in:
Omar Roth 2018-03-29 19:03:00 -05:00
parent 385d6301a3
commit 60360ee2ae
1 changed files with 7 additions and 7 deletions

View File

@ -207,14 +207,14 @@ def get_video(id, client, db, refresh = true)
video = db.query_one("SELECT * FROM videos WHERE id = $1", id, as: Video) video = db.query_one("SELECT * FROM videos WHERE id = $1", id, as: Video)
# 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.second
begin begin
video = fetch_video(id, client) video = fetch_video(id, client)
video_array = video.to_a[1..-1] video_array = video.to_a
args = arg_array(video_array) args = arg_array(video_array[1..-1], 2)
db.exec("UPDATE videos SET (id,info,updated,title,views,likes,dislikes,wilson_score,published,description,language)\ db.exec("UPDATE videos SET (info,updated,title,views,likes,dislikes,wilson_score,published,description,language)\
= (#{args}) WHERE id = '#{video.id}'", video_array) = (#{args}) WHERE id = $1", video_array)
rescue ex rescue ex
db.exec("DELETE FROM videos * WHERE id = $1", id) db.exec("DELETE FROM videos * WHERE id = $1", id)
end end
@ -417,9 +417,9 @@ def number_with_separator(number)
number.to_s.reverse.gsub(/(\d{3})(?=\d)/, "\\1,").reverse number.to_s.reverse.gsub(/(\d{3})(?=\d)/, "\\1,").reverse
end end
def arg_array(array) def arg_array(array, start = 1)
args = [] of String args = [] of String
(1..array.size).each { |i| args << "($#{i})" } (start..array.size + start - 1).each { |i| args << "($#{i})" }
args = args.join(",") args = args.join(",")
return args return args