mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2023-06-08.git
synced 2024-08-15 00:53:38 +00:00
Update DB calls for 0.31.0
This commit is contained in:
parent
be2ee33273
commit
4361ea9686
5 changed files with 11 additions and 49 deletions
|
@ -1396,7 +1396,7 @@ post "/login" do |env|
|
|||
user_array[4] = user_array[4].to_json
|
||||
args = arg_array(user_array)
|
||||
|
||||
PG_DB.exec("INSERT INTO users VALUES (#{args})", user_array)
|
||||
PG_DB.exec("INSERT INTO users VALUES (#{args})", args: user_array)
|
||||
PG_DB.exec("INSERT INTO session_ids VALUES ($1, $2, $3)", sid, email, Time.utc)
|
||||
|
||||
view_name = "subscriptions_#{sha256(user.email)}"
|
||||
|
@ -2908,7 +2908,7 @@ post "/feed/webhook/:token" do |env|
|
|||
PG_DB.exec("INSERT INTO channel_videos VALUES (#{args}) \
|
||||
ON CONFLICT (id) DO UPDATE SET title = $2, published = $3, \
|
||||
updated = $4, ucid = $5, author = $6, length_seconds = $7, \
|
||||
live_now = $8, premiere_timestamp = $9, views = $10", video_array)
|
||||
live_now = $8, premiere_timestamp = $9, views = $10", args: video_array)
|
||||
|
||||
# Update all users affected by insert
|
||||
if emails.empty?
|
||||
|
|
|
@ -179,14 +179,14 @@ def get_channel(id, db, refresh = true, pull_all_videos = true)
|
|||
args = arg_array(channel_array)
|
||||
|
||||
db.exec("INSERT INTO channels VALUES (#{args}) \
|
||||
ON CONFLICT (id) DO UPDATE SET author = $2, updated = $3", channel_array)
|
||||
ON CONFLICT (id) DO UPDATE SET author = $2, updated = $3", args: channel_array)
|
||||
end
|
||||
else
|
||||
channel = fetch_channel(id, db, pull_all_videos: pull_all_videos)
|
||||
channel_array = channel.to_a
|
||||
args = arg_array(channel_array)
|
||||
|
||||
db.exec("INSERT INTO channels VALUES (#{args})", channel_array)
|
||||
db.exec("INSERT INTO channels VALUES (#{args})", args: channel_array)
|
||||
end
|
||||
|
||||
return channel
|
||||
|
@ -275,7 +275,7 @@ def fetch_channel(ucid, db, pull_all_videos = true, locale = nil)
|
|||
db.exec("INSERT INTO channel_videos VALUES (#{args}) \
|
||||
ON CONFLICT (id) DO UPDATE SET title = $2, published = $3, \
|
||||
updated = $4, ucid = $5, author = $6, length_seconds = $7, \
|
||||
live_now = $8, views = $10", video_array)
|
||||
live_now = $8, views = $10", args: video_array)
|
||||
|
||||
# Update all users affected by insert
|
||||
if emails.empty?
|
||||
|
@ -343,7 +343,7 @@ def fetch_channel(ucid, db, pull_all_videos = true, locale = nil)
|
|||
db.exec("INSERT INTO channel_videos VALUES (#{args}) \
|
||||
ON CONFLICT (id) DO UPDATE SET title = $2, published = $3, \
|
||||
updated = $4, ucid = $5, author = $6, length_seconds = $7, \
|
||||
live_now = $8, views = $10", video_array)
|
||||
live_now = $8, views = $10", args: video_array)
|
||||
|
||||
# Update all users affected by insert
|
||||
if emails.empty?
|
||||
|
|
|
@ -237,41 +237,3 @@ class HTTP::Client
|
|||
response
|
||||
end
|
||||
end
|
||||
|
||||
# https://github.com/will/crystal-pg/pull/171
|
||||
class PG::Statement < ::DB::Statement
|
||||
protected def perform_query(args : Enumerable) : ResultSet
|
||||
params = args.map { |arg| PQ::Param.encode(arg) }
|
||||
conn = self.conn
|
||||
conn.send_parse_message(@sql)
|
||||
conn.send_bind_message params
|
||||
conn.send_describe_portal_message
|
||||
conn.send_execute_message
|
||||
conn.send_sync_message
|
||||
conn.expect_frame PQ::Frame::ParseComplete
|
||||
conn.expect_frame PQ::Frame::BindComplete
|
||||
frame = conn.read
|
||||
case frame
|
||||
when PQ::Frame::RowDescription
|
||||
fields = frame.fields
|
||||
when PQ::Frame::NoData
|
||||
fields = nil
|
||||
else
|
||||
raise "expected RowDescription or NoData, got #{frame}"
|
||||
end
|
||||
ResultSet.new(self, fields)
|
||||
rescue IO::Error
|
||||
raise DB::ConnectionLost.new(connection)
|
||||
end
|
||||
|
||||
protected def perform_exec(args : Enumerable) : ::DB::ExecResult
|
||||
result = perform_query(args)
|
||||
result.each { }
|
||||
::DB::ExecResult.new(
|
||||
rows_affected: result.rows_affected,
|
||||
last_insert_id: 0_i64 # postgres doesn't support this
|
||||
)
|
||||
rescue IO::Error
|
||||
raise DB::ConnectionLost.new(connection)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -107,7 +107,7 @@ def get_user(sid, headers, db, refresh = true)
|
|||
args = arg_array(user_array)
|
||||
|
||||
db.exec("INSERT INTO users VALUES (#{args}) \
|
||||
ON CONFLICT (email) DO UPDATE SET updated = $1, subscriptions = $3", user_array)
|
||||
ON CONFLICT (email) DO UPDATE SET updated = $1, subscriptions = $3", args: user_array)
|
||||
|
||||
db.exec("INSERT INTO session_ids VALUES ($1,$2,$3) \
|
||||
ON CONFLICT (id) DO NOTHING", sid, user.email, Time.utc)
|
||||
|
@ -126,7 +126,7 @@ def get_user(sid, headers, db, refresh = true)
|
|||
args = arg_array(user.to_a)
|
||||
|
||||
db.exec("INSERT INTO users VALUES (#{args}) \
|
||||
ON CONFLICT (email) DO UPDATE SET updated = $1, subscriptions = $3", user_array)
|
||||
ON CONFLICT (email) DO UPDATE SET updated = $1, subscriptions = $3", args: user_array)
|
||||
|
||||
db.exec("INSERT INTO session_ids VALUES ($1,$2,$3) \
|
||||
ON CONFLICT (id) DO NOTHING", sid, user.email, Time.utc)
|
||||
|
@ -295,7 +295,7 @@ def get_subscription_feed(db, user, max_results = 40, page = 1)
|
|||
|
||||
args = arg_array(notifications)
|
||||
|
||||
notifications = db.query_all("SELECT * FROM channel_videos WHERE id IN (#{args}) ORDER BY published DESC", notifications, as: ChannelVideo)
|
||||
notifications = db.query_all("SELECT * FROM channel_videos WHERE id IN (#{args}) ORDER BY published DESC", args: notifications, as: ChannelVideo)
|
||||
videos = [] of ChannelVideo
|
||||
|
||||
notifications.sort_by! { |video| video.published }.reverse!
|
||||
|
|
|
@ -900,7 +900,7 @@ def get_video(id, db, refresh = true, region = nil, force_refresh = false)
|
|||
db.exec("UPDATE videos SET (info,updated,title,views,likes,dislikes,wilson_score,\
|
||||
published,description,language,author,ucid,allowed_regions,is_family_friendly,\
|
||||
genre,genre_url,license,sub_count_text,author_thumbnail)\
|
||||
= (#{args}) WHERE id = $1", video_array)
|
||||
= (#{args}) WHERE id = $1", args: video_array)
|
||||
rescue ex
|
||||
db.exec("DELETE FROM videos * WHERE id = $1", id)
|
||||
raise ex
|
||||
|
@ -913,7 +913,7 @@ def get_video(id, db, refresh = true, region = nil, force_refresh = false)
|
|||
args = arg_array(video_array)
|
||||
|
||||
if !region
|
||||
db.exec("INSERT INTO videos VALUES (#{args}) ON CONFLICT (id) DO NOTHING", video_array)
|
||||
db.exec("INSERT INTO videos VALUES (#{args}) ON CONFLICT (id) DO NOTHING", args: video_array)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue