diff --git a/config.ru b/config.ru index ac9fde5dd74851a99f99144d4a97035aa90cc958..f265ccd1eb4f2641edc24a12d103376c5bccddb6 100644 --- a/config.ru +++ b/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)