-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: support for cursors on store API #1024
Conversation
size-limit report 📦
|
When adding |
export async function createCursor( | ||
message: DecodedMessage, | ||
pubsubTopic: string = DefaultPubSubTopic | ||
): Promise<Index> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
non-blocking: Did you find the answer to why the cursor was implemented as an object and not a string/hash?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does contain a digest. At the end of the day, it matches the protobuf interface. I think the inner work of the Index
type should be a black box for the API consumer:
- Call
createCursor
and getsomething
- Pass
something
to the store query
If you have an idea how to improve the API, please do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had discussed this with @jm-clius earlier and there is indeed an ideal way possible to have the entire arg as a digest of all the 4 fields.
This is simply a design that was implemented earlier and could be changed in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cc @LNSD
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: I plan to simplify the current protocol as part of the nwaku v0.14.0 release. And streamline the cursor handling is one of the reasons behind this protocol overhaul.
/** | ||
* Cursor as an index to start a query from. | ||
*/ | ||
cursor?: Index; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
non-blocking: did you consider not allowing startTime
and endTime
if cursor
set? Could be worth ensuring with a type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea 👍 @danisharora099
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We mean accepting either the timeFilter
or the cursor
arg here?
cc @felicio
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We mean accepting either the timeFilter or the cursor arg here?
Yeah, but I saw the @LNSD's comment about it being allowed since then, which made me reconsider.
@LNSD thanks for the great summary at waku-org/nwaku#1400 (comment). Please,
- What is meant by "If the cursor timestamps are not included in the time range"? Which cursor timestamps? Is it only
senderTime
for clients? - If so, shouldn't the
senderTime
,digest
andpubsubTopic
be actually required, and not optional, fields for clients? - And in that case, would there really be use for queries combining "time range + cursor"? Or is it then rather "end time + cursor"?
- Would/should these combined queries be covered by the planned prepared statements and bindings too?
Problem
The most efficient way to query Waku Store is using a cursor.
The current
WakuStore
API does not enable a cursor to be passed, the cursor is only used for pagination after the first page is received.Solution
The cursor is constructed using data from a given Waku message. When using the cursor, the store returns messages starting from the cursor, which is the message used to build the cursor.
If the library consumer knows from which message they want to query, then a cursor could be used from the first page.
This could be useful in the following scenarios:
Notes