multi: add more logging when fetching invoices and payments.

This commit is contained in:
ziggie
2025-04-18 15:27:00 +02:00
parent 729c84bee3
commit 440ed31419
7 changed files with 134 additions and 6 deletions

View File

@@ -484,16 +484,25 @@ func (i *InvoiceRegistry) dispatchToClients(event *invoiceEvent) {
func (i *InvoiceRegistry) deliverBacklogEvents(ctx context.Context,
client *InvoiceSubscription) error {
log.Debugf("Collecting added invoices since %v for client %v",
client.addIndex, client.id)
addEvents, err := i.idb.InvoicesAddedSince(ctx, client.addIndex)
if err != nil {
return err
}
log.Debugf("Collecting settled invoices since %v for client %v",
client.settleIndex, client.id)
settleEvents, err := i.idb.InvoicesSettledSince(ctx, client.settleIndex)
if err != nil {
return err
}
log.Debugf("Delivering %d added invoices and %d settled invoices "+
"for client %v", len(addEvents), len(settleEvents), client.id)
// If we have any to deliver, then we'll append them to the end of the
// notification queue in order to catch up the client before delivering
// any new notifications.

View File

@@ -24,6 +24,10 @@ const (
// defaultQueryPaginationLimit is used in the LIMIT clause of the SQL
// queries to limit the number of rows returned.
defaultQueryPaginationLimit = 100
// invoiceScanBatchSize is the number we use limiting the logging output
// when scanning invoices.
invoiceScanBatchSize = 1000
)
// SQLInvoiceQueries is an interface that defines the set of operations that can
@@ -785,7 +789,11 @@ func (i *SQLStore) FetchPendingInvoices(ctx context.Context) (
func (i *SQLStore) InvoicesSettledSince(ctx context.Context, idx uint64) (
[]Invoice, error) {
var invoices []Invoice
var (
invoices []Invoice
start = time.Now()
processedCount int
)
if idx == 0 {
return invoices, nil
@@ -819,6 +827,14 @@ func (i *SQLStore) InvoicesSettledSince(ctx context.Context, idx uint64) (
}
invoices = append(invoices, *invoice)
processedCount++
if processedCount%invoiceScanBatchSize == 0 {
log.Debugf("Processed %d settled "+
"invoices since invoice with "+
"settle index %v",
processedCount, idx)
}
}
return len(rows), nil
@@ -873,6 +889,13 @@ func (i *SQLStore) InvoicesSettledSince(ctx context.Context, idx uint64) (
}
invoices = append(invoices, *invoice)
processedCount++
if processedCount%invoiceScanBatchSize == 0 {
log.Debugf("Processed %d settled invoices "+
"since invoice with settle index %v",
processedCount, idx)
}
}
return nil
@@ -884,6 +907,12 @@ func (i *SQLStore) InvoicesSettledSince(ctx context.Context, idx uint64) (
"index (excluding) %d: %w", idx, err)
}
elapsed := time.Since(start)
log.Debugf("Completed scanning invoices settled since index %v: "+
"total_processed=%d, found_invoices=%d, elapsed=%v",
idx, processedCount, len(invoices),
elapsed.Round(time.Millisecond))
return invoices, nil
}
@@ -896,7 +925,11 @@ func (i *SQLStore) InvoicesSettledSince(ctx context.Context, idx uint64) (
func (i *SQLStore) InvoicesAddedSince(ctx context.Context, idx uint64) (
[]Invoice, error) {
var result []Invoice
var (
result []Invoice
start = time.Now()
processedCount int
)
if idx == 0 {
return result, nil
@@ -928,6 +961,13 @@ func (i *SQLStore) InvoicesAddedSince(ctx context.Context, idx uint64) (
}
result = append(result, *invoice)
processedCount++
if processedCount%invoiceScanBatchSize == 0 {
log.Debugf("Processed %d invoices "+
"added since invoice with add "+
"index %v", processedCount, idx)
}
}
return len(rows), nil
@@ -941,6 +981,12 @@ func (i *SQLStore) InvoicesAddedSince(ctx context.Context, idx uint64) (
"index %d: %w", idx, err)
}
elapsed := time.Since(start)
log.Debugf("Completed scanning invoices added since index %v: "+
"total_processed=%d, found_invoices=%d, elapsed=%v",
idx, processedCount, len(result),
elapsed.Round(time.Millisecond))
return result, nil
}