summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOmar Roth <omar@wilbur.localdomain>2020-02-28 11:46:24 -0500
committerOmar Roth <omarroth@protonmail.com>2020-02-28 12:14:29 -0500
commit02fd02d4826c04e3253c57bdafc41ba00398318e (patch)
tree64741e4ee78a128ab0e0cd2b53ad41334aba1ab6 /src
parent239fb0db9447590482fddb3b2e638e882b97847a (diff)
downloadinvidious-02fd02d4826c04e3253c57bdafc41ba00398318e.tar.gz
invidious-02fd02d4826c04e3253c57bdafc41ba00398318e.tar.bz2
invidious-02fd02d4826c04e3253c57bdafc41ba00398318e.zip
Remove DB array concatenation
Diffstat (limited to 'src')
-rw-r--r--src/invidious.cr12
-rw-r--r--src/invidious/channels.cr4
2 files changed, 8 insertions, 8 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index d2ff2a3d..ea8cbcd2 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -468,7 +468,7 @@ get "/watch" do |env|
env.params.query.delete_all("iv_load_policy")
if watched && !watched.includes? id
- PG_DB.exec("UPDATE users SET watched = watched || $1 WHERE email = $2", [id], user.as(User).email)
+ PG_DB.exec("UPDATE users SET watched = array_append(watched, $1) WHERE email = $2", id, user.as(User).email)
end
if notifications && notifications.includes? id
@@ -748,7 +748,7 @@ get "/embed/:id" do |env|
end
# if watched && !watched.includes? id
- # PG_DB.exec("UPDATE users SET watched = watched || $1 WHERE email = $2", [id], user.as(User).email)
+ # PG_DB.exec("UPDATE users SET watched = array_append(watched, $1) WHERE email = $2", id, user.as(User).email)
# end
if notifications && notifications.includes? id
@@ -1243,11 +1243,11 @@ post "/playlist_ajax" do |env|
args = arg_array(video_array)
PG_DB.exec("INSERT INTO playlist_videos VALUES (#{args})", args: video_array)
- PG_DB.exec("UPDATE playlists SET index = array_append(index, $1), video_count = video_count + 1, updated = $2 WHERE id = $3", playlist_video.index, Time.utc, playlist_id)
+ PG_DB.exec("UPDATE playlists SET index = array_append(index, $1), video_count = cardinality(index), updated = $2 WHERE id = $3", playlist_video.index, Time.utc, playlist_id)
when "action_remove_video"
index = env.params.query["set_video_id"]
PG_DB.exec("DELETE FROM playlist_videos * WHERE index = $1", index)
- PG_DB.exec("UPDATE playlists SET index = array_remove(index, $1), video_count = video_count - 1, updated = $2 WHERE id = $3", index, Time.utc, playlist_id)
+ PG_DB.exec("UPDATE playlists SET index = array_remove(index, $1), video_count = cardinality(index), updated = $2 WHERE id = $3", index, Time.utc, playlist_id)
when "action_move_video_before"
# TODO: Playlist stub
end
@@ -2244,7 +2244,7 @@ post "/watch_ajax" do |env|
case action
when "action_mark_watched"
if !user.watched.includes? id
- PG_DB.exec("UPDATE users SET watched = watched || $1 WHERE email = $2", [id], user.email)
+ PG_DB.exec("UPDATE users SET watched = array_append(watched, $1) WHERE email = $2", id, user.email)
end
when "action_mark_unwatched"
PG_DB.exec("UPDATE users SET watched = array_remove(watched, $1) WHERE email = $2", id, user.email)
@@ -3402,7 +3402,7 @@ post "/feed/webhook/:token" do |env|
views: video.views,
)
- emails = PG_DB.query_all("UPDATE users SET notifications = notifications || $1 \
+ emails = PG_DB.query_all("UPDATE users SET notifications = array_append(notifications, $1) \
WHERE updated < $2 AND $3 = ANY(subscriptions) AND $1 <> ALL(notifications) RETURNING email",
video.id, video.published, video.ucid, as: String)
diff --git a/src/invidious/channels.cr b/src/invidious/channels.cr
index cddeed39..e5cfb10f 100644
--- a/src/invidious/channels.cr
+++ b/src/invidious/channels.cr
@@ -273,7 +273,7 @@ def fetch_channel(ucid, db, pull_all_videos = true, locale = nil)
views: views,
)
- emails = db.query_all("UPDATE users SET notifications = notifications || $1 \
+ emails = db.query_all("UPDATE users SET notifications = array_append(notifications, $1) \
WHERE updated < $2 AND $3 = ANY(subscriptions) AND $1 <> ALL(notifications) RETURNING email",
video.id, video.published, ucid, as: String)
@@ -342,7 +342,7 @@ def fetch_channel(ucid, db, pull_all_videos = true, locale = nil)
# We are notified of Red videos elsewhere (PubSub), which includes a correct published date,
# so since they don't provide a published date here we can safely ignore them.
if Time.utc - video.published > 1.minute
- emails = db.query_all("UPDATE users SET notifications = notifications || $1 \
+ emails = db.query_all("UPDATE users SET notifications = array_append(notifications, $1) \
WHERE updated < $2 AND $3 = ANY(subscriptions) AND $1 <> ALL(notifications) RETURNING email",
video.id, video.published, video.ucid, as: String)