feat: pagination order

This commit is contained in:
Richard Ramos 2024-07-19 08:15:53 -04:00
parent 329af027ab
commit 91ec0ce749
No known key found for this signature in database
GPG Key ID: 1CE87DB518195760
2 changed files with 10 additions and 2 deletions

View File

@ -60,6 +60,13 @@ var Pagesize = altsrc.NewUint64Flag(&cli.Uint64Flag{
Destination: &options.PageSize,
})
var Forward = altsrc.NewBoolFlag(&cli.BoolFlag{
Name: "Pagination Order",
Usage: "Indicates if the entries will be traversed in ascending order (true) or descending order (false)",
Destination: &options.Forward,
Value: false,
})
var Storenode = cliutils.NewGenericFlagSingleValue(&cli.GenericFlag{
Name: "storenode",
Usage: "Multiaddr of a peer that supports store protocol",

View File

@ -37,6 +37,7 @@ type Options struct {
Hashes cli.StringSlice
AdvanceCursor bool
PageSize uint64
Forward bool
StoreNode *multiaddr.Multiaddr
UseLegacy bool
QueryTimeout time.Duration
@ -154,7 +155,7 @@ func FetchMessage(ctx context.Context, opts Options) error {
ctx, cancel := context.WithTimeout(context.Background(), options.QueryTimeout)
result, err := wakuNode.Store().Request(ctx, store.MessageHashCriteria{MessageHashes: []pb.MessageHash{pb.ToMessageHash(h)}},
store.WithPeerAddr(*options.StoreNode),
store.WithPaging(false, options.PageSize),
store.WithPaging(options.Forward, options.PageSize),
)
cancel()
if err != nil {
@ -283,7 +284,7 @@ func QueryMessages(ctx context.Context, opts Options) error {
pageCount := 0
if len(result.Messages()) == 0 {
fmt.Println("No messages found (%v)", ellapsed)
fmt.Printf("No messages found (%v)\n", ellapsed)
return nil
}