mirror of
https://github.com/iv-org/invidious.git
synced 2024-12-11 00:34:40 -05:00
search functions: Don't return result count
This is useless, as the items count can be directly acessed using the '.size' method, so use that instead when needed.
This commit is contained in:
parent
971b6ec96f
commit
84cc732281
@ -254,7 +254,7 @@ module Invidious::Routes::API::V1::Channels
|
||||
page = env.params.query["page"]?.try &.to_i?
|
||||
page ||= 1
|
||||
|
||||
count, search_results = channel_search(query, page, ucid)
|
||||
search_results = channel_search(query, page, ucid)
|
||||
JSON.build do |json|
|
||||
json.array do
|
||||
search_results.each do |item|
|
||||
|
@ -32,7 +32,7 @@ module Invidious::Routes::API::V1::Search
|
||||
return error_json(400, ex)
|
||||
end
|
||||
|
||||
count, search_results = search(query, search_params, region).as(Tuple)
|
||||
search_results = search(query, search_params, region)
|
||||
JSON.build do |json|
|
||||
json.array do
|
||||
search_results.each do |item|
|
||||
|
@ -247,15 +247,13 @@ module Invidious::Routes::Playlists
|
||||
query = env.params.query["q"]?
|
||||
if query
|
||||
begin
|
||||
search_query, count, items, operators = process_search_query(query, page, user, region: nil)
|
||||
search_query, items, operators = process_search_query(query, page, user, region: nil)
|
||||
videos = items.select(SearchVideo).map(&.as(SearchVideo))
|
||||
rescue ex
|
||||
videos = [] of SearchVideo
|
||||
count = 0
|
||||
end
|
||||
else
|
||||
videos = [] of SearchVideo
|
||||
count = 0
|
||||
end
|
||||
|
||||
env.set "add_playlist_items", plid
|
||||
|
@ -54,7 +54,7 @@ module Invidious::Routes::Search
|
||||
user = env.get? "user"
|
||||
|
||||
begin
|
||||
search_query, count, videos, operators = process_search_query(query, page, user, region: region)
|
||||
search_query, videos, operators = process_search_query(query, page, user, region: region)
|
||||
rescue ex : ChannelSearchException
|
||||
return error_template(404, "Unable to find channel with id of '#{HTML.escape(ex.channel)}'. Are you sure that's an actual channel id? It should look like 'UC4QobU6STFB0P71PMvOGN5A'.")
|
||||
rescue ex
|
||||
|
@ -5,7 +5,7 @@ class ChannelSearchException < InfoException
|
||||
end
|
||||
end
|
||||
|
||||
def channel_search(query, page, channel)
|
||||
def channel_search(query, page, channel) : Array(SearchItem)
|
||||
response = YT_POOL.client &.get("/channel/#{channel}")
|
||||
|
||||
if response.status_code == 404
|
||||
@ -24,7 +24,7 @@ def channel_search(query, page, channel)
|
||||
continuation_items = response_json["onResponseReceivedActions"]?
|
||||
.try &.[0]["appendContinuationItemsAction"]["continuationItems"]
|
||||
|
||||
return 0, [] of SearchItem if !continuation_items
|
||||
return [] of SearchItem if !continuation_items
|
||||
|
||||
items = [] of SearchItem
|
||||
continuation_items.as_a.select(&.as_h.has_key?("itemSectionRenderer")).each { |item|
|
||||
@ -32,17 +32,16 @@ def channel_search(query, page, channel)
|
||||
.try { |t| items << t }
|
||||
}
|
||||
|
||||
return items.size, items
|
||||
return items
|
||||
end
|
||||
|
||||
def search(query, search_params = produce_search_params(content_type: "all"), region = nil)
|
||||
return 0, [] of SearchItem if query.empty?
|
||||
def search(query, search_params = produce_search_params(content_type: "all"), region = nil) : Array(SearchItem)
|
||||
return [] of SearchItem if query.empty?
|
||||
|
||||
client_config = YoutubeAPI::ClientConfig.new(region: region)
|
||||
initial_data = YoutubeAPI.search(query, search_params, client_config: client_config)
|
||||
items = extract_items(initial_data)
|
||||
|
||||
return items.size, items
|
||||
return extract_items(initial_data)
|
||||
end
|
||||
|
||||
def produce_search_params(page = 1, sort : String = "relevance", date : String = "", content_type : String = "",
|
||||
@ -217,7 +216,7 @@ def process_search_query(query, page, user, region)
|
||||
search_query = (query.split(" ") - operators).join(" ")
|
||||
|
||||
if channel
|
||||
count, items = channel_search(search_query, page, channel)
|
||||
items = channel_search(search_query, page, channel)
|
||||
elsif subscriptions
|
||||
if view_name
|
||||
items = PG_DB.query_all("SELECT id,title,published,updated,ucid,author,length_seconds FROM (
|
||||
@ -227,16 +226,14 @@ def process_search_query(query, page, user, region)
|
||||
as document
|
||||
FROM #{view_name}
|
||||
) v_search WHERE v_search.document @@ plainto_tsquery($1) LIMIT 20 OFFSET $2;", search_query, (page - 1) * 20, as: ChannelVideo)
|
||||
count = items.size
|
||||
else
|
||||
items = [] of ChannelVideo
|
||||
count = 0
|
||||
end
|
||||
else
|
||||
search_params = produce_search_params(page: page, sort: sort, date: date, content_type: content_type,
|
||||
duration: duration, features: features)
|
||||
|
||||
count, items = search(search_query, search_params, region).as(Tuple)
|
||||
items = search(search_query, search_params, region)
|
||||
end
|
||||
|
||||
# Light processing to flatten search results out of Categories.
|
||||
@ -254,5 +251,5 @@ def process_search_query(query, page, user, region)
|
||||
end
|
||||
end
|
||||
|
||||
{search_query, items_without_category.size, items_without_category, operators}
|
||||
{search_query, items_without_category, operators}
|
||||
end
|
||||
|
@ -48,7 +48,7 @@
|
||||
</div>
|
||||
<div class="pure-u-1 pure-u-lg-3-5"></div>
|
||||
<div class="pure-u-1 pure-u-lg-1-5" style="text-align:right">
|
||||
<% if count >= 20 %>
|
||||
<% if videos.size >= 20 %>
|
||||
<a href="/add_playlist_items?list=<%= plid %>&q=<%= URI.encode_www_form(query.not_nil!) %>&page=<%= page + 1 %>">
|
||||
<%= translate(locale, "Next page") %>
|
||||
</a>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<% search_query_encoded = env.get?("search").try { |x| URI.encode_www_form(x.as(String), space_to_plus: true) } %>
|
||||
|
||||
<!-- Search redirection and filtering UI -->
|
||||
<% if count == 0 %>
|
||||
<% if videos.size == 0 %>
|
||||
<h3 style="text-align: center">
|
||||
<a href="/redirect?referer=<%= env.get?("current_page") %>"><%= translate(locale, "Broken? Try another Invidious Instance!") %></a>
|
||||
</h3>
|
||||
@ -98,7 +98,7 @@
|
||||
</details>
|
||||
<% end %>
|
||||
|
||||
<% if count == 0 %>
|
||||
<% if videos.size == 0 %>
|
||||
<hr style="margin: 0;"/>
|
||||
<% else %>
|
||||
<hr/>
|
||||
@ -114,7 +114,7 @@
|
||||
</div>
|
||||
<div class="pure-u-1 pure-u-lg-3-5"></div>
|
||||
<div class="pure-u-1 pure-u-lg-1-5" style="text-align:right">
|
||||
<% if count >= 20 %>
|
||||
<% if videos.size >= 20 %>
|
||||
<a href="/search?q=<%= search_query_encoded %>&page=<%= page + 1 %>">
|
||||
<%= translate(locale, "Next page") %>
|
||||
</a>
|
||||
@ -138,7 +138,7 @@
|
||||
</div>
|
||||
<div class="pure-u-1 pure-u-lg-3-5"></div>
|
||||
<div class="pure-u-1 pure-u-lg-1-5" style="text-align:right">
|
||||
<% if count >= 20 %>
|
||||
<% if videos.size >= 20 %>
|
||||
<a href="/search?q=<%= search_query_encoded %>&page=<%= page + 1 %>">
|
||||
<%= translate(locale, "Next page") %>
|
||||
</a>
|
||||
|
Loading…
Reference in New Issue
Block a user