Skip to content

Make less API calls when syncing a stack - #609

Open
nickborromeo wants to merge 7 commits into
mainfrom
sync-fewer-api-calls
Open

nickborromeo wants to merge 7 commits into
mainfrom
sync-fewer-api-calls

Conversation

@nickborromeo

Copy link
Copy Markdown
Member

When I was looking through the logic of runSync I noticed that we called syncStackPRs multiple times, but we don't really use the result of that call. Since the result is not necessarily needed in the sync process I thought we could just call it once.

Another thing that we were doing is to pull all the stacks of the repository, paginated by 100. Each stack has a distinct number, so instead of pulling in all the stacks, we now just pull that stack by its number.

Lastly there is just some small helper functions added in utils.go

This adds a new struct that will hold information so we can store any
data from an API pull and reuse it.
The main change that is being proposed here is to lower the number of
calls that this function makes via the API.

Prior to this change, it was making
- 3 full stack listings plus 3 lookups per PR

After this change it now just makes
- 1 stack fetch plus 1 lookup per PR
Copilot AI max review requested due to automatic review settings November 1, 2026 01:17
@nickborromeo
nickborromeo requested a review from skarim as a code owner November 1, 2026 01:17

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.

🟡 Changes recommended

The command help and workflow documentation still place PR refresh after pushing, although it now runs before fast-forwarding and rebasing.

1 open issue
What changed in this PR

Reduces GitHub API calls during stack synchronization by fetching tracked stacks directly and reusing PR data from reconciliation.

Changes:

  • Fetch stacks by number instead of scanning all repository stacks.
  • Reuse fetched PR data and remove the post-push PR refresh.
  • Update mocks and regression tests for direct stack lookups and PR-fetch reuse.
File Description
cmd/​utils.go Separates PR fetching from applying state and shares reconciliation results.
cmd/​utils_test.go Updates tests for numbered stack lookups and fallback behavior.
cmd/​sync.go Reuses fetched PR data and makes the post-push step report-only.
cmd/​sync_test.go Verifies PR-fetch reuse and updates stack API mocks.
cmd/​submit_test.go Adapts submit mocks and expectations to direct stack lookups.

Review effort: Max

Comment thread cmd/sync.go
cfg.Printf("")
cfg.Printf("Syncing PRs ...")
_ = syncStackPRs(cfg, s)
cfg.Printf("Reporting PR status ...")

This branch has not been deployed

No deployments
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.

2 participants