paymentsdb: implement DeletePayments for sql backend

This commit is contained in:
ziggie committed 2026-02-25 08:02:16 +01:00
1 parent 53a7877af0
commit ff12082452
4 files changed
+296 -55

No files matched your search

+27 -10
View File
@@ -297,29 +297,46 @@ func (q *Queries) FetchHopsForAttempts(ctx context.Context, htlcAttemptIndices [
return items, nil
}
const fetchHtlcAttemptResolutionsForPayment = `-- name: FetchHtlcAttemptResolutionsForPayment :many
const fetchHtlcAttemptResolutionsForPayments = `-- name: FetchHtlcAttemptResolutionsForPayments :many
SELECT
ha.payment_id,
hr.resolution_type
FROM payment_htlc_attempts ha
LEFT JOIN payment_htlc_attempt_resolutions hr ON hr.attempt_index = ha.attempt_index
WHERE ha.payment_id = $1
ORDER BY ha.attempt_time ASC
WHERE ha.payment_id IN (/*SLICE:payment_ids*/?)
`
// Lightweight query to fetch only HTLC resolution status.
func (q *Queries) FetchHtlcAttemptResolutionsForPayment(ctx context.Context, paymentID int64) ([]sql.NullInt32, error) {
rows, err := q.db.QueryContext(ctx, fetchHtlcAttemptResolutionsForPayment, paymentID)
type FetchHtlcAttemptResolutionsForPaymentsRow struct {
PaymentID int64
ResolutionType sql.NullInt32
}
// Batch query to fetch only HTLC resolution status for multiple payments.
// We don't need to order by payment_id and attempt_time because we will
// group the resolutions by payment_id in the background.
func (q *Queries) FetchHtlcAttemptResolutionsForPayments(ctx context.Context, paymentIds []int64) ([]FetchHtlcAttemptResolutionsForPaymentsRow, error) {
query := fetchHtlcAttemptResolutionsForPayments
var queryParams []interface{}
if len(paymentIds) > 0 {
for _, v := range paymentIds {
queryParams = append(queryParams, v)
}
query = strings.Replace(query, "/*SLICE:payment_ids*/?", makeQueryParams(len(queryParams), len(paymentIds)), 1)
} else {
query = strings.Replace(query, "/*SLICE:payment_ids*/?", "NULL", 1)
}
rows, err := q.db.QueryContext(ctx, query, queryParams...)
if err != nil {
return nil, err
}
defer rows.Close()
var items []sql.NullInt32
var items []FetchHtlcAttemptResolutionsForPaymentsRow
for rows.Next() {
var resolution_type sql.NullInt32
if err := rows.Scan(&resolution_type); err != nil {
var i FetchHtlcAttemptResolutionsForPaymentsRow
if err := rows.Scan(&i.PaymentID, &i.ResolutionType); err != nil {
return nil, err
}
items = append(items, resolution_type)
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
+4 -2
View File
@@ -42,8 +42,10 @@ type Querier interface {
FetchAllInflightAttempts(ctx context.Context) ([]PaymentHtlcAttempt, error)
FetchHopLevelCustomRecords(ctx context.Context, hopIds []int64) ([]PaymentHopCustomRecord, error)
FetchHopsForAttempts(ctx context.Context, htlcAttemptIndices []int64) ([]FetchHopsForAttemptsRow, error)
// Lightweight query to fetch only HTLC resolution status.
FetchHtlcAttemptResolutionsForPayment(ctx context.Context, paymentID int64) ([]sql.NullInt32, error)
// Batch query to fetch only HTLC resolution status for multiple payments.
// We don't need to order by payment_id and attempt_time because we will
// group the resolutions by payment_id in the background.
FetchHtlcAttemptResolutionsForPayments(ctx context.Context, paymentIds []int64) ([]FetchHtlcAttemptResolutionsForPaymentsRow, error)
FetchHtlcAttemptsForPayments(ctx context.Context, paymentIds []int64) ([]FetchHtlcAttemptsForPaymentsRow, error)
FetchPayment(ctx context.Context, paymentIdentifier []byte) (FetchPaymentRow, error)
FetchPaymentLevelFirstHopCustomRecords(ctx context.Context, paymentIds []int64) ([]PaymentFirstHopCustomRecord, error)
+6 -4
View File
@@ -75,14 +75,16 @@ LEFT JOIN payment_htlc_attempt_resolutions hr ON hr.attempt_index = ha.attempt_i
WHERE ha.payment_id IN (sqlc.slice('payment_ids')/*SLICE:payment_ids*/)
ORDER BY ha.payment_id ASC, ha.attempt_time ASC;
-- name: FetchHtlcAttemptResolutionsForPayment :many
-- Lightweight query to fetch only HTLC resolution status.
-- name: FetchHtlcAttemptResolutionsForPayments :many
-- Batch query to fetch only HTLC resolution status for multiple payments.
-- We don't need to order by payment_id and attempt_time because we will
-- group the resolutions by payment_id in the background.
SELECT
ha.payment_id,
hr.resolution_type
FROM payment_htlc_attempts ha
LEFT JOIN payment_htlc_attempt_resolutions hr ON hr.attempt_index = ha.attempt_index
WHERE ha.payment_id = $1
ORDER BY ha.attempt_time ASC;
WHERE ha.payment_id IN (sqlc.slice('payment_ids')/*SLICE:payment_ids*/);
-- name: FetchAllInflightAttempts :many
-- Fetch all inflight attempts across all payments