Skip to content

Commit

Permalink
channeldb: Fixes the count of payments returned by QueryPayments
Browse files Browse the repository at this point in the history
QueryPayments function was changed to return the toyal num of payments
considering the date start and date end restrictions existing on the query
  • Loading branch information
MPins committed Jul 3, 2024
1 parent 71ba355 commit fc41ecc
Showing 1 changed file with 1 addition and 22 deletions.
23 changes: 1 addition & 22 deletions channeldb/payments.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,28 +597,7 @@ func (d *DB) QueryPayments(query PaymentsQuery) (PaymentsResponse, error) {
// literally have to traverse the cursor linearly, which can
// take quite a while. So it's an optional query parameter.
if query.CountTotal {
var (
totalPayments uint64
err error
)
countFn := func(_, _ []byte) error {
totalPayments++

return nil
}

// In non-boltdb database backends, there's a faster
// ForAll query that allows for batch fetching items.
if fastBucket, ok := indexes.(kvdb.ExtendedRBucket); ok {
err = fastBucket.ForAll(countFn)
} else {
err = indexes.ForEach(countFn)
}
if err != nil {
return fmt.Errorf("error counting payments: %w",
err)
}

totalPayments := uint64(len(resp.Payments))
resp.TotalCount = totalPayments
}

Expand Down

0 comments on commit fc41ecc

Please sign in to comment.