Remove string interpolation from SQL queries

pull/3/head
Omar Roth 7 years ago
parent a54f59ad74
commit 8d66493c01

@ -553,8 +553,6 @@ def fetch_channel(id, client, db)
db.exec("UPDATE users SET notifications = notifications || $1 \ db.exec("UPDATE users SET notifications = notifications || $1 \
WHERE updated < $2 AND $3 = ANY(subscriptions) AND $1 <> ALL(notifications)", video_id, published, ucid) 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 # TODO: Update record on conflict
db.exec("INSERT INTO channel_videos VALUES (#{args})\ db.exec("INSERT INTO channel_videos VALUES (#{args})\
ON CONFLICT (id) DO NOTHING", video_array) ON CONFLICT (id) DO NOTHING", video_array)

@ -127,9 +127,9 @@ channel_threads.times do |i|
spawn do spawn do
loop do loop do
query = "SELECT id FROM channels ORDER BY updated \ query = "SELECT id FROM channels ORDER BY updated \
LIMIT (SELECT count(*)/#{channel_threads} FROM channels) \ LIMIT (SELECT count(*)/$2 FROM channels) \
OFFSET (SELECT count(*)*#{i}/#{channel_threads} FROM channels)" OFFSET (SELECT count(*)*$1/$2 FROM channels)"
PG_DB.query(query) do |rs| PG_DB.query(query, i, channel_threads) do |rs|
rs.each do rs.each do
client = get_client(youtube_pool) client = get_client(youtube_pool)
id = rs.read(String) id = rs.read(String)
@ -590,10 +590,10 @@ get "/feed/subscriptions" do |env|
user = get_user(sid, client, headers, PG_DB) user = get_user(sid, client, headers, PG_DB)
youtube_pool << client youtube_pool << client
args = arg_array(user.subscriptions) args = arg_array(user.subscriptions, 3)
offset = (page - 1) * max_results offset = (page - 1) * max_results
videos = PG_DB.query_all("SELECT * FROM channel_videos WHERE ucid IN (#{args}) \ 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) ORDER BY published DESC LIMIT $1 OFFSET $2", [max_results, offset] + user.subscriptions, as: ChannelVideo)
env.set "notifications", 0 env.set "notifications", 0

Loading…
Cancel
Save