Do not try query when values is empty

Stephen Paul Weber created

If there are no values to query with, then the SQL will be invalid and throw an
error, so just return empty for that case.

Change summary

config.ru | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

Detailed changes

config.ru 🔗

@@ -170,16 +170,23 @@ end
 
 class UnknownTransactions
 	def self.from(customer_id, address, tx_hashes)
+		self.for(
+			customer_id,
+			fetch_rows_for(address, tx_hashes).map { |row| row["transaction_id"] }
+		)
+	end
+
+	def self.fetch_rows_for(address, tx_hashes)
 		values = tx_hashes.map do |tx_hash|
 			"('#{DB.escape_string(tx_hash)}/#{DB.escape_string(address)}')"
 		end
-		rows = DB.exec_params(<<-SQL)
+		return [] unless values
+		DB.exec_params(<<-SQL)
 			SELECT transaction_id FROM
 				(VALUES #{values.join(',')}) AS t(transaction_id)
 				LEFT JOIN transactions USING (transaction_id)
 			WHERE transactions.transaction_id IS NULL
 		SQL
-		self.for(customer_id, rows.map { |row| row["transaction_id"] })
 	end
 
 	def self.for(customer_id, transaction_ids)