summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOmar Roth <omarroth@hotmail.com>2018-04-02 18:38:03 -0500
committerOmar Roth <omarroth@hotmail.com>2018-04-02 18:38:03 -0500
commit8d66493c016853937c4595b4c380ec03c5aa1b3c (patch)
tree81d11410f3f653d68e85bc2f6f9ab1355bff22ae /src
parenta54f59ad742af9c8d86a7fe947a48857813609d7 (diff)
downloadinvidious-8d66493c016853937c4595b4c380ec03c5aa1b3c.tar.gz
invidious-8d66493c016853937c4595b4c380ec03c5aa1b3c.tar.bz2
invidious-8d66493c016853937c4595b4c380ec03c5aa1b3c.zip
Remove string interpolation from SQL queries
Diffstat (limited to 'src')
-rw-r--r--src/helpers.cr2
-rw-r--r--src/invidious.cr12
2 files changed, 6 insertions, 8 deletions
diff --git a/src/helpers.cr b/src/helpers.cr
index 47652163..b0c61d27 100644
--- a/src/helpers.cr
+++ b/src/helpers.cr
@@ -553,8 +553,6 @@ def fetch_channel(id, client, db)
db.exec("UPDATE users SET notifications = notifications || $1 \
WHERE updated < $2 AND $3 = ANY(subscriptions) AND $1 <> ALL(notifications)", video_id, published, ucid)
- # UPDATE users SET notifications = notifications || ARRAY['Os9Rypn2rEQ'] WHERE updated < '2018-03-24 20:48:46' AND 'UCSc16oMxxlcJSb9SXkjwMjA' = ANY(subscriptions) AND 'Os9Rypn2rEQ' <> ALL (notifications);
-
# TODO: Update record on conflict
db.exec("INSERT INTO channel_videos VALUES (#{args})\
ON CONFLICT (id) DO NOTHING", video_array)
diff --git a/src/invidious.cr b/src/invidious.cr
index 2f7c3c89..55fe2334 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -127,9 +127,9 @@ channel_threads.times do |i|
spawn do
loop do
query = "SELECT id FROM channels ORDER BY updated \
- LIMIT (SELECT count(*)/#{channel_threads} FROM channels) \
- OFFSET (SELECT count(*)*#{i}/#{channel_threads} FROM channels)"
- PG_DB.query(query) do |rs|
+ LIMIT (SELECT count(*)/$2 FROM channels) \
+ OFFSET (SELECT count(*)*$1/$2 FROM channels)"
+ PG_DB.query(query, i, channel_threads) do |rs|
rs.each do
client = get_client(youtube_pool)
id = rs.read(String)
@@ -590,10 +590,10 @@ get "/feed/subscriptions" do |env|
user = get_user(sid, client, headers, PG_DB)
youtube_pool << client
- args = arg_array(user.subscriptions)
+ args = arg_array(user.subscriptions, 3)
offset = (page - 1) * max_results
- videos = PG_DB.query_all("SELECT * FROM channel_videos WHERE ucid IN (#{args})\
- ORDER BY published DESC LIMIT #{max_results} OFFSET #{offset}", user.subscriptions, as: ChannelVideo)
+ videos = PG_DB.query_all("SELECT * FROM channel_videos WHERE ucid IN (#{args}) \
+ ORDER BY published DESC LIMIT $1 OFFSET $2", [max_results, offset] + user.subscriptions, as: ChannelVideo)
env.set "notifications", 0