Debug SQL query for timestamp adjustment

This commit is contained in:
broquemonsieur 2023-07-23 21:45:00 -07:00
parent ea878e22a1
commit a8c0023eb0
3 changed files with 25 additions and 16 deletions

View File

@ -276,11 +276,11 @@ module Invidious::Database::CompilationVideos
def update_start_timestamp(id : String, starting_timestamp_seconds : Int32) def update_start_timestamp(id : String, starting_timestamp_seconds : Int32)
request = <<-SQL request = <<-SQL
UPDATE compilation_videos UPDATE compilation_videos
SET starting_timestamp_seconds = starting_timestamp_seconds SET starting_timestamp_seconds = $2
WHERE id = $1 WHERE id = $1
SQL SQL
PG_DB.exec(request, id) PG_DB.exec(request, id, starting_timestamp_seconds)
end end
def update_end_timestamp(id : String, ending_timestamp_seconds : Int64) def update_end_timestamp(id : String, ending_timestamp_seconds : Int64)

View File

@ -201,7 +201,7 @@ module Invidious::Routes::Compilations
env.response.content_type = "application/json" env.response.content_type = "application/json"
user = env.get("user").as(User) user = env.get("user").as(User)
compid = env.params.url["compid"]? compid = env.params.query["list"]?
if !compid || compid.empty? if !compid || compid.empty?
return error_json(400, "A compilation ID is required") return error_json(400, "A compilation ID is required")
end end
@ -215,31 +215,37 @@ module Invidious::Routes::Compilations
return error_json(403, "Invalid user") return error_json(403, "Invalid user")
end end
title = env.params.json["title"].try &.as(String).delete("<>").byte_slice(0, 150) || compilation.title #title = env.params.json["title"].try &.as(String).delete("<>").byte_slice(0, 150) || compilation.title
privacy = env.params.json["privacy"]?.try { |p| CompilationPrivacy.parse(p.as(String).downcase) } || compilation.privacy #privacy = env.params.json["privacy"]?.try { |p| CompilationPrivacy.parse(p.as(String).downcase) } || compilation.privacy
if title != compilation.title || #if title != compilation.title ||
privacy != compilation.privacy # privacy != compilation.privacy
updated = Time.utc # updated = Time.utc
else #else
updated = compilation.updated # updated = compilation.updated
end #end
#{1...Invidious::Database::Compilations.count_owned_by(user.email)}.each do |index| #{1...Invidious::Database::Compilations.count_owned_by(user.email)}.each do |index|
# start_timestamp = env.params.json["_start_timestamp"]?.try &.as(String).byte_slice(0, 150) || compilation.title # start_timestamp = env.params.json["_start_timestamp"]?.try &.as(String).byte_slice(0, 150) || compilation.title
compilation_video_cardinality = Invidious::Database::CompilationVideos.select_ids(compid, compilation.index).size
(0..Invidious::Database::Compilations.count_owned_by(user.email)).each do |index| (0..compilation_video_cardinality-1).each do |index|
LOGGER.info("for loop cycle #{index} of #{Invidious::Database::Compilations.count_owned_by(user.email)}")
compilation_video_id = Invidious::Database::CompilationVideos.select_id_from_order_index(order_index: index) compilation_video_id = Invidious::Database::CompilationVideos.select_id_from_order_index(order_index: index)
#compilation_video_index = Invidious::Database::CompilationVideos.select_index_from_order_index(order_index: index) #compilation_video_index = Invidious::Database::CompilationVideos.select_index_from_order_index(order_index: index)
compilation_video = Invidious::Database::CompilationVideos.select(compid, compilation.index, 0, 1) compilation_video = Invidious::Database::CompilationVideos.select(compid, compilation.index, 0, 1)
#numerical_string = index.to #numerical_string = index.to
json_timestamp_query = index.to_s + "_start_timestamp" json_timestamp_query = index.to_s + "_start_timestamp"
start_timestamp = env.params.json[json_timestamp_query]?.try &.as(String).byte_slice(0, 8) LOGGER.info("adjust #{json_timestamp_query} ")
start_timestamp = env.params.body[json_timestamp_query]?.try &.as(String).byte_slice(0, 8)
LOGGER.info("render #{env.params.body[json_timestamp_query]} ")
if !start_timestamp.nil? && !compilation_video_id.nil? if !start_timestamp.nil? && !compilation_video_id.nil?
LOGGER.info("adjust #{json_timestamp_query} which renders as #{start_timestamp}")
start_timestamp_seconds = decode_length_seconds(start_timestamp) start_timestamp_seconds = decode_length_seconds(start_timestamp)
if !start_timestamp_seconds.nil? if !start_timestamp_seconds.nil?
if start_timestamp_seconds >= 0 && start_timestamp_seconds <= compilation_video[0].starting_timestamp_seconds if start_timestamp_seconds >= 0 && start_timestamp_seconds <= compilation_video[0].length_seconds
Invidious::Database::CompilationVideos.update_start_timestamp(compilation_video_id, start_timestamp_seconds) LOGGER.info("adjusting timestamps to #{start_timestamp_seconds} which is #{start_timestamp_seconds.to_i}")
Invidious::Database::CompilationVideos.update_start_timestamp(compilation_video_id, start_timestamp_seconds.to_i)
end end
end end
end end
@ -256,6 +262,8 @@ module Invidious::Routes::Compilations
end end
end end
env.redirect "/compilation?list=#{compid}"
end end
@ -369,6 +377,7 @@ module Invidious::Routes::Compilations
when "action_edit_compilation" when "action_edit_compilation"
# TODO: Compilation stub # TODO: Compilation stub
LOGGER.info("Begin handling of Compilation edit") LOGGER.info("Begin handling of Compilation edit")
when "action_add_video" when "action_add_video"
if compilation.index.size >= CONFIG.compilation_length_limit if compilation.index.size >= CONFIG.compilation_length_limit
if redirect if redirect

View File

@ -58,7 +58,7 @@
if item.id.starts_with? "RD" if item.id.starts_with? "RD"
link_url = "/mix?list=#{item.id}&continuation=#{URI.parse(item.thumbnail || "/vi/-----------").request_target.split("/")[2]}" link_url = "/mix?list=#{item.id}&continuation=#{URI.parse(item.thumbnail || "/vi/-----------").request_target.split("/")[2]}"
else else
link_url = "/playlist?list=#{item.id}" link_url = "/compilation?list=#{item.id}"
end end
-%> -%>