paymentsdb: implement FetchInFlightPayments for sql backend

This commit is contained in:
ziggie committed 2026-02-25 08:02:16 +01:00
1 parent 82ee78c5ef
commit 969b00e4a5
5 files changed
+288 -40

No files matched your search

+22 -11
View File
@@ -40,15 +40,6 @@ FROM payments p
LEFT JOIN payment_intents i ON i.payment_id = p.id
WHERE p.payment_identifier = $1;
-- name: FetchPaymentsByIDs :many
SELECT
sqlc.embed(p),
i.intent_type AS "intent_type",
i.intent_payload AS "intent_payload"
FROM payments p
LEFT JOIN payment_intents i ON i.payment_id = p.id
WHERE p.id IN (sqlc.slice('payment_ids')/*SLICE:payment_ids*/);
-- name: CountPayments :one
SELECT COUNT(*) FROM payments;
@@ -86,8 +77,26 @@ FROM payment_htlc_attempts ha
LEFT JOIN payment_htlc_attempt_resolutions hr ON hr.attempt_index = ha.attempt_index
WHERE ha.payment_id IN (sqlc.slice('payment_ids')/*SLICE:payment_ids*/);
-- name: FetchPaymentsByIDs :many
-- Batch fetch payment and intent data for a set of payment IDs.
-- Used to avoid fetching redundant payment data when processing multiple
-- attempts for the same payment.
SELECT
p.id,
p.amount_msat,
p.created_at,
p.payment_identifier,
p.fail_reason,
pi.intent_type,
pi.intent_payload
FROM payments p
LEFT JOIN payment_intents pi ON pi.payment_id = p.id
WHERE p.id IN (sqlc.slice('payment_ids')/*SLICE:payment_ids*/)
ORDER BY p.id ASC;
-- name: FetchAllInflightAttempts :many
-- Fetch all inflight attempts across all payments
-- Fetch all inflight attempts with their payment data using pagination.
-- Returns attempt data joined with payment and intent data to avoid separate queries.
SELECT
ha.id,
ha.attempt_index,
@@ -104,7 +113,9 @@ WHERE NOT EXISTS (
SELECT 1 FROM payment_htlc_attempt_resolutions hr
WHERE hr.attempt_index = ha.attempt_index
)
ORDER BY ha.attempt_index ASC;
AND ha.attempt_index > $1
ORDER BY ha.attempt_index ASC
LIMIT $2;
-- name: FetchHopsForAttempts :many
SELECT