-
Notifications
You must be signed in to change notification settings - Fork 0
perf: pagination and bounded scans at millions of rows #432
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
6edd0cc
perf(storage): narrow projection for job and DLQ listings
pratyush618 59acbae
perf(storage): chunk mass delete, purge, and cancel loops
pratyush618 710ba8e
perf(redis): bound history purges and log queries with batched scans
pratyush618 d8a85a5
feat(storage): keyset pagination for job, DLQ, and archive listings
pratyush618 f2db305
feat(workflows): keyset pagination for workflow runs
pratyush618 3ceb821
feat(python): cursor-paginated list APIs
pratyush618 6ca1a0a
fix(storage): reject malformed keyset cursors
pratyush618 6738db3
fix(storage): drop non-positive limits before keyset queries
pratyush618 b97e494
fix(redis): recheck job status after hydration in list_jobs_after
pratyush618 bda427e
fix(redis): use checked arithmetic for DLQ expiry
pratyush618 4c53f83
perf(redis): seek keyset pages by rank
pratyush618 612e513
perf(redis): window and pipeline filtered log scans
pratyush618 fc08e18
docs(storage): note the Redis keyset pagination exception
pratyush618 b626f1e
test(storage): assert keyset paging covers every created row
pratyush618 18866b7
fix(dashboard): allow requesting the first cursor page
pratyush618 95a35b8
test(redis): page a same-score archived batch
pratyush618 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| //! Opaque keyset-pagination cursor shared by every SDK binding. | ||
| //! | ||
| //! A cursor encodes the `(sort_key, id)` of the last row of a page — the sort | ||
| //! key being the listing's ordering column (`created_at`/`completed_at`/ | ||
| //! `failed_at`, a non-negative millis timestamp) and `id` the row's UUIDv7 / | ||
| //! DLQ id. Neither contains a `:`, so a single split round-trips unambiguously | ||
| //! with no base64. Callers must treat the string as opaque and pass it back | ||
| //! verbatim; the format may gain a version prefix later. | ||
|
|
||
| use crate::error::{QueueError, Result}; | ||
|
|
||
| /// Encode a `(sort_key, id)` keyset cursor as an opaque string. | ||
| pub fn encode_cursor(sort_key: i64, id: &str) -> String { | ||
| format!("{sort_key}:{id}") | ||
| } | ||
|
|
||
| /// Decode a cursor produced by [`encode_cursor`]. Returns `Other` on malformed | ||
| /// input — treat it like any other bad-request error. | ||
| pub fn decode_cursor(cursor: &str) -> Result<(i64, &str)> { | ||
| let (key, id) = cursor | ||
| .split_once(':') | ||
| .ok_or_else(|| QueueError::Other(format!("invalid cursor: {cursor}")))?; | ||
| let sort_key: i64 = key | ||
| .parse() | ||
| .map_err(|_| QueueError::Other(format!("invalid cursor: {cursor}")))?; | ||
| // A cursor this crate did not encode: sort keys are non-negative millis and | ||
| // every row has an id. Reject rather than page from a position no row holds. | ||
| if sort_key < 0 || id.is_empty() { | ||
| return Err(QueueError::Other(format!("invalid cursor: {cursor}"))); | ||
| } | ||
| Ok((sort_key, id)) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn round_trips() { | ||
| let s = encode_cursor(1_720_000_000_123, "0190a1b2-c3d4-7e5f-8a9b-0c1d2e3f4a5b"); | ||
| let (key, id) = decode_cursor(&s).unwrap(); | ||
| assert_eq!(key, 1_720_000_000_123); | ||
| assert_eq!(id, "0190a1b2-c3d4-7e5f-8a9b-0c1d2e3f4a5b"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn rejects_malformed() { | ||
| assert!(decode_cursor("nocolon").is_err()); | ||
| assert!(decode_cursor("notanint:abc").is_err()); | ||
| assert!(decode_cursor("-1:abc").is_err()); | ||
| assert!(decode_cursor("1:").is_err()); | ||
| } | ||
| } | ||
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.