Skip to content

Page datastore queries that fetched all applications - #7234

Open
srinivasr wants to merge 3 commits into
pipe-cd:masterfrom
srinivasr:fix/list-applications-pagination
Open

Page datastore queries that fetched all applications#7234
srinivasr wants to merge 3 commits into
pipe-cd:masterfrom
srinivasr:fix/list-applications-pagination

Conversation

@srinivasr

Copy link
Copy Markdown

What this PR does:

Fixes unbounded datastore queries in ListApplications (piped and web) and CreateDeploymentChain. These endpoints ran one query with no limit and returned every matching row; now they fetch pages of 100 and combine them before responding. Cursor paging needs a stable sort, so these queries order by Id.

ListEvents gets the same treatment, with a default of newest-first when a request leaves the order unset — without that default, paging would error on the second page.

Adds the composite indexes these query shapes need to firestoreindexensurer.

Why we need it:

A project with thousands of applications pays for all of them on every piped sync. The TODO in ListApplications flagged this; until the reads are chunked, the query grows with the project and eventually risks datastore timeouts.

Which issue(s) this PR fixes:

Fixes #7051

Does this PR introduce a user-facing change?:

No breaking changes. Responses still contain the complete aggregated list — they're just fetched from the backend in chunks.

  • How are users affected by this change: Firestore users: firestoreindexensurer creates the new composite indexes automatically on control-plane startup, but GCP index builds take time — calls fail with FAILED_PRECONDITION until each index finishes building. MySQL users need no action.
  • Is this breaking change: No
  • How to migrate (if breaking change): N/A

ListApplications for piped, ListApplications for web, and the
application lookup in CreateDeploymentChain ran one query with no limit
and returned every matching row. A project with thousands of
applications pays for all of them on every sync even though the RPC
responses have no cursor field and cannot page.

These now fetch 100 rows at a time and combine the pages before
responding.

Paging by cursor needs a fixed sort order, so the queries sort by Id.

ListEvents also pages now. It defaults to newest first when a request
leaves the order unset, which previously errored on the second page.

Added the composite indexes these query shapes need to
firestoreindexensurer; Firestore does not create them automatically.

Fixes pipe-cd#7051

Signed-off-by: srinivasr <sriniv4sreddy@gmail.com>
@srinivasr
srinivasr requested a review from a team as a code owner August 24, 2026 20:10
@srinivasr
srinivasr requested review from armistcxy, khanhtc1202 and t-kikuc and a lite review from Copilot August 24, 2026 20:10
@netlify

netlify Bot commented Aug 24, 2026

Copy link
Copy Markdown

Deploy Preview for pipecd-site ready!

Name Link
🔨 Latest commit 75187c6
🔍 Latest deploy log https://app.netlify.com/projects/pipecd-site/deploys/6a8d4762823ba30008619caa
😎 Deploy Preview https://deploy-preview-7234--pipecd-site.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses unbounded datastore reads in PipeCD’s control-plane gRPC APIs by switching several “list everything” queries to internal cursor-based pagination, aggregating results server-side to preserve existing RPC contracts while avoiding single large queries (notably improving piped sync behavior for large projects).

Changes:

  • Page and aggregate results for ListApplications (piped + web) and CreateDeploymentChain application lookups, using stable ordering and a fixed per-page limit.
  • Page and aggregate ListEvents, including a default stable ordering when the request does not specify one.
  • Add Firestore composite indexes required by the new query shapes and update index parsing tests; add a unit test for paged ListApplications.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pkg/app/server/grpcapi/web_api.go Switch WebAPI ListApplications to internally page via listAllApplications with a fixed limit.
pkg/app/server/grpcapi/piped_api.go Add paging + stable ordering for piped ListApplications, ListEvents, and application listing used by CreateDeploymentChain.
pkg/app/server/grpcapi/list_applications_test.go Add unit tests verifying multi-page aggregation behavior for piped ListApplications.
pkg/app/server/grpcapi/application_lister.go Introduce a shared helper to page/aggregate application lists via datastore cursor.
pkg/app/server/grpcapi/event_lister.go Introduce a shared helper to page/aggregate event lists via datastore cursor.
pkg/app/ops/firestoreindexensurer/indexes.json Add composite indexes for the new ordered/paged Firestore query patterns.
pkg/app/ops/firestoreindexensurer/indexes_test.go Update expected parsed index list to include the new indexes.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pkg/app/server/grpcapi/piped_api.go Outdated
Comment thread pkg/app/server/grpcapi/piped_api.go
Comment thread pkg/app/server/grpcapi/piped_api.go
@srinivasr
srinivasr requested a balanced review from Copilot August 25, 2026 05:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@srinivasr
srinivasr requested a balanced review from Copilot August 25, 2026 05:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

srinivasr and others added 2 commits August 25, 2026 12:52
…ering

- Move listApplicationsPageSize to application_lister.go for colocation
- Explicitly handle ListOrder_NONE in ListEvents to avoid masking client bugs
- Add unit tests for ListEvents pagination and default ordering behavior

Signed-off-by: srinivasr <sriniv4sreddy@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: piped ListApplications silently truncates paginated results

2 participants