paymentsdb: rename paymentsBatchData

We rename this variable to paymentsDetailsData because we will
also need to batch load the core payment and intent data in
future commits and this renaming should make it clear that this
does match payment related data but not the core data which is
in the payment and in the intent table.
This commit is contained in:
ziggie committed 2026-02-25 08:02:15 +01:00
1 parent 5d328c976e
commit caf73c59da
1 file changed
+15 -12
+15 -12
View File
@@ -161,8 +161,11 @@ func fetchPaymentWithCompleteData(ctx context.Context,
return buildPaymentFromBatchData(dbPayment, batchData) return buildPaymentFromBatchData(dbPayment, batchData)
} }
// paymentsBatchData holds all the batch-loaded data for multiple payments. // paymentsDetailsData holds all the batch-loaded data for multiple payments.
type paymentsBatchData struct { // This does not include the core payment and intent data which is fetched
// separately. It includes the additional data like attempts, hops, hop custom
// records, and route custom records.
type paymentsDetailsData struct {
// paymentCustomRecords maps payment ID to its custom records. // paymentCustomRecords maps payment ID to its custom records.
paymentCustomRecords map[int64][]sqlc.PaymentFirstHopCustomRecord paymentCustomRecords map[int64][]sqlc.PaymentFirstHopCustomRecord
@@ -185,7 +188,7 @@ type paymentsBatchData struct {
// the given payment IDs. // the given payment IDs.
func loadPaymentCustomRecords(ctx context.Context, func loadPaymentCustomRecords(ctx context.Context,
cfg *sqldb.QueryConfig, db SQLQueries, paymentIDs []int64, cfg *sqldb.QueryConfig, db SQLQueries, paymentIDs []int64,
batchData *paymentsBatchData) error { batchData *paymentsDetailsData) error {
return sqldb.ExecuteBatchQuery( return sqldb.ExecuteBatchQuery(
ctx, cfg, paymentIDs, ctx, cfg, paymentIDs,
@@ -219,7 +222,7 @@ func loadPaymentCustomRecords(ctx context.Context,
// payment IDs. // payment IDs.
func loadHtlcAttempts(ctx context.Context, cfg *sqldb.QueryConfig, func loadHtlcAttempts(ctx context.Context, cfg *sqldb.QueryConfig,
db SQLQueries, paymentIDs []int64, db SQLQueries, paymentIDs []int64,
batchData *paymentsBatchData) ([]int64, error) { batchData *paymentsDetailsData) ([]int64, error) {
var allAttemptIndices []int64 var allAttemptIndices []int64
@@ -252,7 +255,7 @@ func loadHtlcAttempts(ctx context.Context, cfg *sqldb.QueryConfig,
// It uses a batch query to fetch all hops for the given attempt indices. // It uses a batch query to fetch all hops for the given attempt indices.
func loadHopsForAttempts(ctx context.Context, cfg *sqldb.QueryConfig, func loadHopsForAttempts(ctx context.Context, cfg *sqldb.QueryConfig,
db SQLQueries, attemptIndices []int64, db SQLQueries, attemptIndices []int64,
batchData *paymentsBatchData) ([]int64, error) { batchData *paymentsDetailsData) ([]int64, error) {
var hopIDs []int64 var hopIDs []int64
@@ -285,7 +288,7 @@ func loadHopsForAttempts(ctx context.Context, cfg *sqldb.QueryConfig,
// loadHopCustomRecords loads hop-level custom records for all hops. It uses // loadHopCustomRecords loads hop-level custom records for all hops. It uses
// a batch query to fetch all custom records for the given hop IDs. // a batch query to fetch all custom records for the given hop IDs.
func loadHopCustomRecords(ctx context.Context, cfg *sqldb.QueryConfig, func loadHopCustomRecords(ctx context.Context, cfg *sqldb.QueryConfig,
db SQLQueries, hopIDs []int64, batchData *paymentsBatchData) error { db SQLQueries, hopIDs []int64, batchData *paymentsDetailsData) error {
return sqldb.ExecuteBatchQuery( return sqldb.ExecuteBatchQuery(
ctx, cfg, hopIDs, ctx, cfg, hopIDs,
@@ -320,7 +323,7 @@ func loadHopCustomRecords(ctx context.Context, cfg *sqldb.QueryConfig,
// attempt indices. // attempt indices.
func loadRouteCustomRecords(ctx context.Context, cfg *sqldb.QueryConfig, func loadRouteCustomRecords(ctx context.Context, cfg *sqldb.QueryConfig,
db SQLQueries, attemptIndices []int64, db SQLQueries, attemptIndices []int64,
batchData *paymentsBatchData) error { batchData *paymentsDetailsData) error {
return sqldb.ExecuteBatchQuery( return sqldb.ExecuteBatchQuery(
ctx, cfg, attemptIndices, ctx, cfg, attemptIndices,
@@ -349,9 +352,9 @@ func loadRouteCustomRecords(ctx context.Context, cfg *sqldb.QueryConfig,
// loadPaymentsBatchData loads all related data for multiple payments in batch. // loadPaymentsBatchData loads all related data for multiple payments in batch.
// It uses a batch queries to fetch all data for the given payment IDs. // It uses a batch queries to fetch all data for the given payment IDs.
func loadPaymentsBatchData(ctx context.Context, cfg *sqldb.QueryConfig, func loadPaymentsBatchData(ctx context.Context, cfg *sqldb.QueryConfig,
db SQLQueries, paymentIDs []int64) (*paymentsBatchData, error) { db SQLQueries, paymentIDs []int64) (*paymentsDetailsData, error) {
batchData := &paymentsBatchData{ batchData := &paymentsDetailsData{
paymentCustomRecords: make( paymentCustomRecords: make(
map[int64][]sqlc.PaymentFirstHopCustomRecord, map[int64][]sqlc.PaymentFirstHopCustomRecord,
), ),
@@ -425,7 +428,7 @@ func loadPaymentsBatchData(ctx context.Context, cfg *sqldb.QueryConfig,
// buildPaymentFromBatchData builds a complete MPPayment from a database payment // buildPaymentFromBatchData builds a complete MPPayment from a database payment
// and pre-loaded batch data. // and pre-loaded batch data.
func buildPaymentFromBatchData(dbPayment sqlc.PaymentAndIntent, func buildPaymentFromBatchData(dbPayment sqlc.PaymentAndIntent,
batchData *paymentsBatchData) (*MPPayment, error) { batchData *paymentsDetailsData) (*MPPayment, error) {
// The query will only return BOLT 11 payment intents or intents with // The query will only return BOLT 11 payment intents or intents with
// no intent type set. // no intent type set.
@@ -559,7 +562,7 @@ func (s *SQLStore) QueryPayments(ctx context.Context, query Query) (Response,
// batchDataFunc loads all related data for a batch of payments. // batchDataFunc loads all related data for a batch of payments.
batchDataFunc := func(ctx context.Context, paymentIDs []int64) ( batchDataFunc := func(ctx context.Context, paymentIDs []int64) (
*paymentsBatchData, error) { *paymentsDetailsData, error) {
return loadPaymentsBatchData( return loadPaymentsBatchData(
ctx, s.cfg.QueryCfg, db, paymentIDs, ctx, s.cfg.QueryCfg, db, paymentIDs,
@@ -570,7 +573,7 @@ func (s *SQLStore) QueryPayments(ctx context.Context, query Query) (Response,
// data. // data.
processPayment := func(ctx context.Context, processPayment := func(ctx context.Context,
dbPayment sqlc.FilterPaymentsRow, dbPayment sqlc.FilterPaymentsRow,
batchData *paymentsBatchData) error { batchData *paymentsDetailsData) error {
// Build the payment from the pre-loaded batch data. // Build the payment from the pre-loaded batch data.
mpPayment, err := buildPaymentFromBatchData( mpPayment, err := buildPaymentFromBatchData(