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.
This commit is contained in:
ziggie
2025-08-13 08:50:58 +02:00
parent 5f3055944a
commit 4bb21a7284
3 changed files with 8 additions and 8 deletions

View File

@@ -553,7 +553,7 @@ func (d *DB) QueryInvoices(_ context.Context, q invpkg.InvoiceQuery) (
// Create a paginator which reads from our add index bucket with // Create a paginator which reads from our add index bucket with
// the parameters provided by the invoice query. // the parameters provided by the invoice query.
paginator := newPaginator( paginator := NewPaginator(
invoiceAddIndex.ReadCursor(), q.Reversed, q.IndexOffset, invoiceAddIndex.ReadCursor(), q.Reversed, q.IndexOffset,
q.NumMaxInvoices, q.NumMaxInvoices,
) )
@@ -603,7 +603,7 @@ func (d *DB) QueryInvoices(_ context.Context, q invpkg.InvoiceQuery) (
// Query our paginator using accumulateInvoices to build up a // Query our paginator using accumulateInvoices to build up a
// set of invoices. // set of invoices.
if err := paginator.query(accumulateInvoices); err != nil { if err := paginator.Query(accumulateInvoices); err != nil {
return err return err
} }

View File

@@ -16,9 +16,9 @@ type paginator struct {
totalItems uint64 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. // in pages.
func newPaginator(c kvdb.RCursor, reversed bool, func NewPaginator(c kvdb.RCursor, reversed bool,
indexOffset, totalItems uint64) paginator { indexOffset, totalItems uint64) paginator {
return paginator{ return paginator{
@@ -105,14 +105,14 @@ func (p paginator) cursorStart() ([]byte, []byte) {
return indexKey, indexValue 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 // 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 // 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 // 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 // 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 // whether the item was added. This is required to allow the paginator to
// determine when the response has the maximum number of required items. // 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() indexKey, indexValue := p.cursorStart()
var totalItems int var totalItems int

View File

@@ -1205,13 +1205,13 @@ func (p *KVPaymentsDB) QueryPayments(_ context.Context,
// Create a paginator which reads from our sequence index bucket // Create a paginator which reads from our sequence index bucket
// with the parameters provided by the payments query. // with the parameters provided by the payments query.
paginator := newPaginator( paginator := NewPaginator(
indexes.ReadCursor(), query.Reversed, query.IndexOffset, indexes.ReadCursor(), query.Reversed, query.IndexOffset,
query.MaxPayments, query.MaxPayments,
) )
// Run a paginated query, adding payments to our response. // 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 return err
} }