Add indexed, timestamped, cursor-paginated instance listing APIs#182
Open
Copilot wants to merge 1 commit into
Open
Add indexed, timestamped, cursor-paginated instance listing APIs#182Copilot wants to merge 1 commit into
Copilot wants to merge 1 commit into
Conversation
Copilot
AI
changed the title
[WIP] Update df.instances to support efficient pagination for external clients
Add indexed, timestamped, cursor-paginated instance listing APIs
May 27, 2026
Re-implements the stale PR #182 on current main. - Add df.list_instances_paginated() with keyset (cursor) pagination ordered by (created_at DESC, id DESC), returning total_count and next_cursor for fetching subsequent pages. - Extend df.list_instances() with created_at / completed_at columns and a stable (created_at DESC, id DESC) order. - Add idx_instances_created_at_desc_id so paging stays an index scan. - Add upgrade DDL to sql/pg_durable--0.2.3--0.2.4.sql (index, the drop/recreate of df.list_instances for its new return shape, and the new df.list_instances_paginated binding); verified Scenario A/B1/B2. - Allowlist the standalone-upgrade-script PS014 finding for the index in scripts/run-pgspot.sh (same false positive as the PS002 entries). - Add E2E test 50_list_instances_paginated.sql and update USER_GUIDE, CHANGELOG, and docs/upgrade-testing.md. Drops PR #182's edit to the df.grant_usage() per-function allowlist, which was removed in 0.2.4 (#242), and fixes the new_backend_provider() call to pass the provider schema.
cffae03 to
610c8b8
Compare
Contributor
|
Consider combining this PR and #186. |
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
df.instanceslisting was expensive for external clients because chronological reads had no supporting index,df.list_instanceshad no server-side pagination, and timestamps were omitted from the response. This made efficient page-by-page UI listing and metadata display harder than necessary.Changes
Schema / index
idx_instances_created_at_desc_idondf.instances(created_at DESC, id).df.list_instancescontract updatecreated_atandcompleted_at.ORDER BY created_at DESC, id DESCfor a deterministic total order.New paginated API
df.list_instances_paginated(status_filter, limit_count, after_cursor).(created_at DESC, id DESC)with alimit + 1lookahead.total_count, andnext_cursor(NULLwhen exhausted).status_filterunder existing RLS behavior.Upgrade & migration
sql/pg_durable--0.2.3--0.2.4.sql(the active unreleased cycle): the index, a drop/recreate ofdf.list_instancesfor its new return shape, and the newdf.list_instances_paginatedbinding.scripts/test-upgrade.sh— 36/36 pass.docs/upgrade-testing.md.PS014finding for the index inscripts/run-pgspot.sh(a plain btree index with no user-defined functions; same false-positive class as the existingPS002entries).Docs
USER_GUIDE.mdandCHANGELOG.mdfor the new/expanded monitoring surface.Testing
tests/e2e/sql/50_list_instances_paginated.sql: starts instances, pages through all of them with a small page size, and asserts the paginated output matchesdf.list_instances()order exactly with correcttotal_countandnext_cursorsemantics (no gaps or duplicates).list_instancesconsumers still pass (05_monitoring_and_explain,22_cancel_status_consistency).cargo fmt,cargo clippy, the upgrade suite, and the pgspot gate all pass.Usage
Notes for reviewers
list_instances_paginatedis a separate function rather than folding pagination intolist_instances, to avoid changing the existing function's argument signature.get_instance_infolookup (unchanged from existinglist_instancesbehavior; not optimized here).created_at::text || '|' || id; it round-trips through thetimestamptzkeyset predicate (validated by the E2E test) but is not an opaque token.