mirror of
https://gitea.invidious.io/iv-org/invidious.git
synced 2024-08-15 00:53:41 +00:00
Clean useless database arguments (1/5)
This commit is contained in:
parent
6704ce3214
commit
9bad7e2940
4 changed files with 14 additions and 14 deletions
|
@ -603,7 +603,7 @@ post "/subscription_ajax" do |env|
|
||||||
case action
|
case action
|
||||||
when "action_create_subscription_to_channel"
|
when "action_create_subscription_to_channel"
|
||||||
if !user.subscriptions.includes? channel_id
|
if !user.subscriptions.includes? channel_id
|
||||||
get_channel(channel_id, PG_DB, false, false)
|
get_channel(channel_id, false, false)
|
||||||
Invidious::Database::Users.subscribe_channel(user, channel_id)
|
Invidious::Database::Users.subscribe_channel(user, channel_id)
|
||||||
end
|
end
|
||||||
when "action_remove_subscriptions"
|
when "action_remove_subscriptions"
|
||||||
|
@ -757,7 +757,7 @@ post "/data_control" do |env|
|
||||||
user.subscriptions += body["subscriptions"].as_a.map(&.as_s)
|
user.subscriptions += body["subscriptions"].as_a.map(&.as_s)
|
||||||
user.subscriptions.uniq!
|
user.subscriptions.uniq!
|
||||||
|
|
||||||
user.subscriptions = get_batch_channels(user.subscriptions, PG_DB, false, false)
|
user.subscriptions = get_batch_channels(user.subscriptions, false, false)
|
||||||
|
|
||||||
Invidious::Database::Users.update_subscriptions(user)
|
Invidious::Database::Users.update_subscriptions(user)
|
||||||
end
|
end
|
||||||
|
@ -829,7 +829,7 @@ post "/data_control" do |env|
|
||||||
end
|
end
|
||||||
user.subscriptions.uniq!
|
user.subscriptions.uniq!
|
||||||
|
|
||||||
user.subscriptions = get_batch_channels(user.subscriptions, PG_DB, false, false)
|
user.subscriptions = get_batch_channels(user.subscriptions, false, false)
|
||||||
|
|
||||||
Invidious::Database::Users.update_subscriptions(user)
|
Invidious::Database::Users.update_subscriptions(user)
|
||||||
when "import_freetube"
|
when "import_freetube"
|
||||||
|
@ -838,7 +838,7 @@ post "/data_control" do |env|
|
||||||
end
|
end
|
||||||
user.subscriptions.uniq!
|
user.subscriptions.uniq!
|
||||||
|
|
||||||
user.subscriptions = get_batch_channels(user.subscriptions, PG_DB, false, false)
|
user.subscriptions = get_batch_channels(user.subscriptions, false, false)
|
||||||
|
|
||||||
Invidious::Database::Users.update_subscriptions(user)
|
Invidious::Database::Users.update_subscriptions(user)
|
||||||
when "import_newpipe_subscriptions"
|
when "import_newpipe_subscriptions"
|
||||||
|
@ -857,7 +857,7 @@ post "/data_control" do |env|
|
||||||
end
|
end
|
||||||
user.subscriptions.uniq!
|
user.subscriptions.uniq!
|
||||||
|
|
||||||
user.subscriptions = get_batch_channels(user.subscriptions, PG_DB, false, false)
|
user.subscriptions = get_batch_channels(user.subscriptions, false, false)
|
||||||
|
|
||||||
Invidious::Database::Users.update_subscriptions(user)
|
Invidious::Database::Users.update_subscriptions(user)
|
||||||
when "import_newpipe"
|
when "import_newpipe"
|
||||||
|
@ -876,7 +876,7 @@ post "/data_control" do |env|
|
||||||
user.subscriptions += db.query_all("SELECT url FROM subscriptions", as: String).map(&.lchop("https://www.youtube.com/channel/"))
|
user.subscriptions += db.query_all("SELECT url FROM subscriptions", as: String).map(&.lchop("https://www.youtube.com/channel/"))
|
||||||
user.subscriptions.uniq!
|
user.subscriptions.uniq!
|
||||||
|
|
||||||
user.subscriptions = get_batch_channels(user.subscriptions, PG_DB, false, false)
|
user.subscriptions = get_batch_channels(user.subscriptions, false, false)
|
||||||
|
|
||||||
Invidious::Database::Users.update_subscriptions(user)
|
Invidious::Database::Users.update_subscriptions(user)
|
||||||
|
|
||||||
|
|
|
@ -114,7 +114,7 @@ class ChannelRedirect < Exception
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_batch_channels(channels, db, refresh = false, pull_all_videos = true, max_threads = 10)
|
def get_batch_channels(channels, refresh = false, pull_all_videos = true, max_threads = 10)
|
||||||
finished_channel = Channel(String | Nil).new
|
finished_channel = Channel(String | Nil).new
|
||||||
|
|
||||||
spawn do
|
spawn do
|
||||||
|
@ -130,7 +130,7 @@ def get_batch_channels(channels, db, refresh = false, pull_all_videos = true, ma
|
||||||
active_threads += 1
|
active_threads += 1
|
||||||
spawn do
|
spawn do
|
||||||
begin
|
begin
|
||||||
get_channel(ucid, db, refresh, pull_all_videos)
|
get_channel(ucid, refresh, pull_all_videos)
|
||||||
finished_channel.send(ucid)
|
finished_channel.send(ucid)
|
||||||
rescue ex
|
rescue ex
|
||||||
finished_channel.send(nil)
|
finished_channel.send(nil)
|
||||||
|
@ -151,21 +151,21 @@ def get_batch_channels(channels, db, refresh = false, pull_all_videos = true, ma
|
||||||
return final
|
return final
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_channel(id, db, refresh = true, pull_all_videos = true)
|
def get_channel(id, refresh = true, pull_all_videos = true)
|
||||||
if channel = Invidious::Database::Channels.select(id)
|
if channel = Invidious::Database::Channels.select(id)
|
||||||
if refresh && Time.utc - channel.updated > 10.minutes
|
if refresh && Time.utc - channel.updated > 10.minutes
|
||||||
channel = fetch_channel(id, db, pull_all_videos: pull_all_videos)
|
channel = fetch_channel(id, pull_all_videos: pull_all_videos)
|
||||||
Invidious::Database::Channels.insert(channel, update_on_conflict: true)
|
Invidious::Database::Channels.insert(channel, update_on_conflict: true)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
channel = fetch_channel(id, db, pull_all_videos: pull_all_videos)
|
channel = fetch_channel(id, pull_all_videos: pull_all_videos)
|
||||||
Invidious::Database::Channels.insert(channel)
|
Invidious::Database::Channels.insert(channel)
|
||||||
end
|
end
|
||||||
|
|
||||||
return channel
|
return channel
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_channel(ucid, db, pull_all_videos = true, locale = nil)
|
def fetch_channel(ucid, pull_all_videos = true, locale = nil)
|
||||||
LOGGER.debug("fetch_channel: #{ucid}")
|
LOGGER.debug("fetch_channel: #{ucid}")
|
||||||
LOGGER.trace("fetch_channel: #{ucid} : pull_all_videos = #{pull_all_videos}, locale = #{locale}")
|
LOGGER.trace("fetch_channel: #{ucid} : pull_all_videos = #{pull_all_videos}, locale = #{locale}")
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ module Invidious::Routes::API::V1::Authenticated
|
||||||
ucid = env.params.url["ucid"]
|
ucid = env.params.url["ucid"]
|
||||||
|
|
||||||
if !user.subscriptions.includes? ucid
|
if !user.subscriptions.includes? ucid
|
||||||
get_channel(ucid, PG_DB, false, false)
|
get_channel(ucid, false, false)
|
||||||
Invidious::Database::Users.subscribe_channel(user, ucid)
|
Invidious::Database::Users.subscribe_channel(user, ucid)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ def fetch_user(sid, headers, db)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
channels = get_batch_channels(channels, db, false, false)
|
channels = get_batch_channels(channels, false, false)
|
||||||
|
|
||||||
email = feed.xpath_node(%q(//a[@class="yt-masthead-picker-header yt-masthead-picker-active-account"]))
|
email = feed.xpath_node(%q(//a[@class="yt-masthead-picker-header yt-masthead-picker-active-account"]))
|
||||||
if email
|
if email
|
||||||
|
|
Loading…
Reference in a new issue