fix: after filter with limit returns oldest records instead of newest in list endpoints - #2351
Open
lav45 wants to merge 2 commits into
Open
fix: after filter with limit returns oldest records instead of newest in list endpoints#2351lav45 wants to merge 2 commits into
lav45 wants to merge 2 commits into
Conversation
Contributor
|
Hi! Thanks for the PR! This is a known behavior with our API. Unfortunately, because we have customers who depend on this current API behavior, we haven't been able to make changes yet to make things more intuitive. Stay tuned, though, as we hope to have a solution in the near future. The way you can work around this for now, as you may have already discovered, is to pass |
Author
|
It is possible to start forming v2.0.0-RC for now ;) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
When using the after query parameter together with limit in list endpoints (GET /app/{appId}/msg, GET /app/{appId}/endpoint/{endpointId}/msg), the response returns the oldest records in the time window instead of the newest.
Example with 5 messages (msg1 oldest → msg5 newest):
The bug is in filter_and_paginate_time_limited (server/svix-server/src/v1/utils/mod.rs:227). When after is passed without an iterator, the query uses ORDER BY id ASC expecting an in-memory reverse afterward. However, data.truncate(limit) runs
before data.reverse() in list_response_inner, so the newest records are discarded before the reversal can recover them.
Solution
Remove the after-only case (None, None, Some(_)) from the ASC branch so it falls through to ORDER BY id DESC — the same ordering used by all other cases. This makes truncate correctly retain the newest records, and no reversal is needed.
The after filter still applies its lower-bound WHERE id > start_id(after) constraint unchanged, so the time-window semantics are preserved. Pagination via iterator and prev_iterator continues to work correctly.