Skip to content
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

fix: Respect limits on batched messages #90

Merged
merged 4 commits into from
Oct 13, 2023
Merged

Conversation

nplasterer
Copy link
Contributor

fixes #89

Respects limit when batching messages

@nplasterer nplasterer self-assigned this Oct 12, 2023
@nplasterer nplasterer marked this pull request as ready for review October 12, 2023 20:59
@nplasterer nplasterer requested review from jhaaaa and a team as code owners October 12, 2023 20:59
requests.add(req);
if (res.pagingInfo.hasLimit() &&
res.envelopes.length >= res.pagingInfo.limit &&
res.pagingInfo.limit < 100) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flutter sets the default limit to 100 if no limit is set. So tests were failing as it would break out and not cursor further for more than 100 envelopes. This protects against that case. And from someone setting a limit larger than we currently request for.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might make sense to leave this as a comment for future maintainers?

Also, should it be <= 100, and > res.pagingInfo.limit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No since 100 is the default if we set it to equal it will always catch this case and not cursor for things that aren't limited.

requests.add(req);
if (res.pagingInfo.hasLimit() &&
res.envelopes.length >= res.pagingInfo.limit &&
res.pagingInfo.limit < 100) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might make sense to leave this as a comment for future maintainers?

Also, should it be <= 100, and > res.pagingInfo.limit?

Comment on lines +122 to +125
if (res.pagingInfo.hasLimit() &&
res.envelopes.length >= res.pagingInfo.limit &&
res.pagingInfo.limit < 100) {
var envelopes = res.envelopes.take(res.pagingInfo.limit).toList();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the server yielding more than limit results in a page? This seems like a bug in the query implementation. There's an inherent ambiguity in batch querying) but the proto definition makes clear that it's a per-query pagination and this lib constructs each QueryRequest within the Batch to include its own limit -- so I'm not sure why the server is ignoring it.

I don't think we should implement this here -- it breaks pagination: since we didn't yield all the received envelopes, the next-page request cursor becomes invalid (this seems like it could cause non-contiguous message histories which become permanent gaps in apps that assume a contiguous history on first pull and then use fetch-since-last-message to incrementally grow the archive). And even if pagination worked, papering over the server-bug with a client-side fix is a bummer because the app still pays the full the price for transport/decode of the full list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This for the most part is how it's implemented in JS, Kotlin, and Swift.
https://github.com/xmtp/xmtp-js/blob/main/src/ApiClient.ts#L325-L337
https://github.com/xmtp/xmtp-android/blob/main/library/src/main/java/org/xmtp/android/library/ApiClient.kt#L132-L135
The flutter SDK is written differently than the other SDKs so maybe I'm not translating between them correctly but this does fix it.

I don't think we should block this PR for a improvement to the backend. But agree we should probably open an issue for that as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's how they do/should implement batch queries though:
https://github.com/xmtp/xmtp-js/blob/main/src/ApiClient.ts#L441

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The more I dig into this the more I think it's broken. The limit is referred to as pageSize in js which would indicate more of a page size and less of a limit. How many items do you want per page and not how many items do you want period. I still think this is how we want to enforce limit without the backend backing but now that I remember from the last time looking into this I think limit is actually treated like a pageSize on the backend.

@nplasterer
Copy link
Contributor Author

I'm going to merge this as is but flag that this is somewhere that some investigation/fixing should probably happen on the backend.

@nplasterer nplasterer merged commit 9075969 into main Oct 13, 2023
1 check passed
@nplasterer nplasterer deleted the np/respect-limit branch October 13, 2023 05:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Listing messages does not respect the limit parameter
3 participants