Debug the DB methods for compilations

This commit is contained in:
broquemonsieur 2023-07-23 12:39:47 -07:00
parent 60a184eda3
commit ea878e22a1
3 changed files with 58 additions and 33 deletions

View File

@ -217,6 +217,26 @@ module Invidious::Database::CompilationVideos
return PG_DB.query_all(request, compid, index, limit, offset, as: CompilationVideo) return PG_DB.query_all(request, compid, index, limit, offset, as: CompilationVideo)
end end
def select_id_from_order_index(order_index : Int32)
request = <<-SQL
SELECT id FROM compilation_videos
WHERE order_index = $1
LIMIT 1
SQL
return PG_DB.query_one?(request, order_index, as: String)
end
def select_index_from_order_index(order_index : Int32)
request = <<-SQL
SELECT index FROM compilation_videos
WHERE order_index = $1
LIMIT 1
SQL
return PG_DB.query_one?(request, order_index, as: VideoIndex)
end
def select_index(compid : String, vid : String) : Int64? def select_index(compid : String, vid : String) : Int64?
request = <<-SQL request = <<-SQL
SELECT index FROM compilation_videos SELECT index FROM compilation_videos
@ -253,10 +273,23 @@ module Invidious::Database::CompilationVideos
# Update # Update
# ------------------- # -------------------
def update_start_timestamp(compid : String, index : VideoIndex, starting_timestamp_seconds : Int64) 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 = starting_timestamp_seconds
WHERE id = $2 WHERE id = $1
SQL
PG_DB.exec(request, id)
end
def update_end_timestamp(id : String, ending_timestamp_seconds : Int64)
request = <<-SQL
UPDATE compilation_videos
SET ending_timestamp_seconds = ending_timestamp_seconds
WHERE id = $1
SQL
PG_DB.exec(request, id)
end end
end end

View File

@ -225,33 +225,39 @@ module Invidious::Routes::Compilations
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
(1..Invidious::Database::Compilations.count_owned_by(user.email)).each do |index| { (0..Invidious::Database::Compilations.count_owned_by(user.email)).each do |index|
compilation_video = Invidious::Database::CompilationVideos.select(order_index: index) compilation_video_id = Invidious::Database::CompilationVideos.select_id_from_order_index(order_index: index)
start_timestamp = env.params.json[index+"_start_timestamp"]?.try &.as(String).byte_slice(0, 8) #compilation_video_index = Invidious::Database::CompilationVideos.select_index_from_order_index(order_index: index)
if !start_timestamp.empty? compilation_video = Invidious::Database::CompilationVideos.select(compid, compilation.index, 0, 1)
#numerical_string = index.to
json_timestamp_query = index.to_s + "_start_timestamp"
start_timestamp = env.params.json[json_timestamp_query]?.try &.as(String).byte_slice(0, 8)
if !start_timestamp.nil? && !compilation_video_id.nil?
start_timestamp_seconds = decode_length_seconds(start_timestamp) start_timestamp_seconds = decode_length_seconds(start_timestamp)
if !start_timestamp_seconds.empty if !start_timestamp_seconds.nil?
if start_timestamp_seconds >= 0 && start_timestamp_seconds <= compilation_video if start_timestamp_seconds >= 0 && start_timestamp_seconds <= compilation_video[0].starting_timestamp_seconds
Invidious::Database::CompilationVideos.update_start_timestamp(compid, compilation_video.index, start_timestamp_seconds) Invidious::Database::CompilationVideos.update_start_timestamp(compilation_video_id, start_timestamp_seconds)
end end
end end
end end
end_timestamp = env.params.json[index+"_end_timestamp"]?.try &.as(String).byte_slice(0, 8) json_timestamp_query = index.to_s + "_end_timestamp"
if !end_timestamp.empty? end_timestamp = env.params.json[json_timestamp_query]?.try &.as(String).byte_slice(0, 8)
if !end_timestamp.nil? && !compilation_video_id.nil?
end_timestamp_seconds = decode_length_seconds(end_timestamp) end_timestamp_seconds = decode_length_seconds(end_timestamp)
if !end_timestamp_seconds.empty if !end_timestamp_seconds.nil?
if end_timestamp_seconds >= 0 && end_timestamp_seconds <= compilation_video if end_timestamp_seconds >= 0 && end_timestamp_seconds <= compilation_video[0].ending_timestamp_seconds
Invidious::Database::CompilationVideos.update_end_timestamp(compid, compilation_video.index, end_timestamp_seconds) Invidious::Database::CompilationVideos.update_end_timestamp(compilation_video_id, end_timestamp_seconds)
end end
end end
end end
}
end
end
def self.add_compilation_items_page(env) def self.add_compilation_items_page(env)
LOGGER.info("13. add_compilation_items") LOGGER.info("13. add_compilation_items")

View File

@ -53,7 +53,7 @@
<p><%= translate_count(locale, "generic_channels_count", item.channel_count, NumberFormatting::Separator) %></p> <p><%= translate_count(locale, "generic_channels_count", item.channel_count, NumberFormatting::Separator) %></p>
<%- end -%> <%- end -%>
</div> </div>
<% when SearchPlaylist, InvidiousPlaylist %> <% when SearchPlaylist, InvidiousPlaylist, InvidiousCompilation %>
<%- <%-
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]}"
@ -87,20 +87,6 @@
</p> </p>
</a></div> </a></div>
</div> </div>
<% when InvidiousCompilation %>
<% link_url = "/compilation?list=#{item.id}" %>
<a style="width:100%" href="<%= link_url %>">
<% if !env.get("preferences").as(Preferences).thin_mode %>
<div class="thumbnail">
<img loading="lazy" tabindex="-1" class="thumbnail" src="<%= URI.parse(item.thumbnail || "/").request_target %>" alt="" />
<p class="length"><%= translate_count(locale, "generic_videos_count", item.video_count, NumberFormatting::Separator) %></p>
</div>
<% end %>
<p dir="auto"><%= HTML.escape(item.title) %></p>
</a>
<a href="/channel/<%= item.ucid %>">
<p dir="auto"><b><%= HTML.escape(item.author) %><% if !item.is_a?(InvidiousCompilation) && !item.is_a?(InvidiousPlaylist) && !item.author_verified.nil? && item.author_verified %>&nbsp;<i class="icon ion ion-md-checkmark-circle"></i><% end %></b></p>
</a>
<% when Category %> <% when Category %>
<% else %> <% else %>
<%- <%-