From 4bb21a7284fd2560e182d185fe2dcc63268d3c1f Mon Sep 17 00:00:00 2001 From: ziggie Date: Wed, 13 Aug 2025 08:50:58 +0200 Subject: [PATCH] channeldb: export pagination method We export some methods related to the pagination logic be the kv store implemenation of the payment data will live in another package. --- channeldb/invoices.go | 4 ++-- channeldb/paginate.go | 8 ++++---- channeldb/payments_kv_store.go | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/channeldb/invoices.go b/channeldb/invoices.go index 161fa4a2e..ab8d1426f 100644 --- a/channeldb/invoices.go +++ b/channeldb/invoices.go @@ -553,7 +553,7 @@ func (d *DB) QueryInvoices(_ context.Context, q invpkg.InvoiceQuery) ( // Create a paginator which reads from our add index bucket with // the parameters provided by the invoice query. - paginator := newPaginator( + paginator := NewPaginator( invoiceAddIndex.ReadCursor(), q.Reversed, q.IndexOffset, q.NumMaxInvoices, ) @@ -603,7 +603,7 @@ func (d *DB) QueryInvoices(_ context.Context, q invpkg.InvoiceQuery) ( // Query our paginator using accumulateInvoices to build up a // set of invoices. - if err := paginator.query(accumulateInvoices); err != nil { + if err := paginator.Query(accumulateInvoices); err != nil { return err } diff --git a/channeldb/paginate.go b/channeldb/paginate.go index 496c236e0..dbb3548eb 100644 --- a/channeldb/paginate.go +++ b/channeldb/paginate.go @@ -16,9 +16,9 @@ type paginator struct { totalItems uint64 } -// newPaginator returns a struct which can be used to query an indexed bucket +// NewPaginator returns a struct which can be used to query an indexed bucket // in pages. -func newPaginator(c kvdb.RCursor, reversed bool, +func NewPaginator(c kvdb.RCursor, reversed bool, indexOffset, totalItems uint64) paginator { return paginator{ @@ -105,14 +105,14 @@ func (p paginator) cursorStart() ([]byte, []byte) { return indexKey, indexValue } -// query gets the start point for our index offset and iterates through keys +// Query gets the start point for our index offset and iterates through keys // in our index until we reach the total number of items required for the query // or we run out of cursor values. This function takes a fetchAndAppend function // which is responsible for looking up the entry at that index, adding the entry // to its set of return items (if desired) and return a boolean which indicates // whether the item was added. This is required to allow the paginator to // determine when the response has the maximum number of required items. -func (p paginator) query(fetchAndAppend func(k, v []byte) (bool, error)) error { +func (p paginator) Query(fetchAndAppend func(k, v []byte) (bool, error)) error { indexKey, indexValue := p.cursorStart() var totalItems int diff --git a/channeldb/payments_kv_store.go b/channeldb/payments_kv_store.go index cf2ca918b..d18616cb0 100644 --- a/channeldb/payments_kv_store.go +++ b/channeldb/payments_kv_store.go @@ -1205,13 +1205,13 @@ func (p *KVPaymentsDB) QueryPayments(_ context.Context, // Create a paginator which reads from our sequence index bucket // with the parameters provided by the payments query. - paginator := newPaginator( + paginator := NewPaginator( indexes.ReadCursor(), query.Reversed, query.IndexOffset, query.MaxPayments, ) // Run a paginated query, adding payments to our response. - if err := paginator.query(accumulatePayments); err != nil { + if err := paginator.Query(accumulatePayments); err != nil { return err }