Skip to content

Commit 67dd2b4

Browse files
committed
db: use prepared statements rather than crafted argument list
1 parent ce4a523 commit 67dd2b4

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/invidious/database/channels.cr

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,13 @@ module Invidious::Database::Channels
7777

7878
def select(ids : Array(String)) : Array(InvidiousChannel)?
7979
return [] of InvidiousChannel if ids.empty?
80-
values = ids.map { |id| %(('#{id}')) }.join(",")
8180

8281
request = <<-SQL
8382
SELECT * FROM channels
84-
WHERE id = ANY(VALUES #{values})
83+
WHERE id = ANY($1)
8584
SQL
8685

87-
return PG_DB.query_all(request, as: InvidiousChannel)
86+
return PG_DB.query_all(request, ids, as: InvidiousChannel)
8887
end
8988
end
9089

@@ -127,11 +126,11 @@ module Invidious::Database::ChannelVideos
127126

128127
request = <<-SQL
129128
SELECT * FROM channel_videos
130-
WHERE id IN (#{arg_array(ids)})
129+
WHERE id = ANY($1)
131130
ORDER BY published DESC
132131
SQL
133132

134-
return PG_DB.query_all(request, args: ids, as: ChannelVideo)
133+
return PG_DB.query_all(request, ids, as: ChannelVideo)
135134
end
136135

137136
def select_notfications(ucid : String, since : Time) : Array(ChannelVideo)

0 commit comments

Comments
 (0)