Skip to content

Optimize API refresh: separate PR-level and repo-level updates, add check runs to GraphQL batch#226

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/optimize-api-refresh-methods
Draft

Optimize API refresh: separate PR-level and repo-level updates, add check runs to GraphQL batch#226
Copilot wants to merge 3 commits intomainfrom
copilot/optimize-api-refresh-methods

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 22, 2026

Batch refresh was setting checks_passed/failed/skipped and behind_by to 0 on every refresh due to missing data in the GraphQL query. No efficient path existed to update behind_by for all PRs in a repo when the base branch advanced.

Changes

fetch_multiple_prs_batch() — 2-pass GraphQL (was 1 incomplete pass)

  • Pass 1: Adds headCommit: commits(last: 1) { statusCheckRollup { contexts } } — check runs now populated from statusCheckRollup (was hardcoded 0)
  • Pass 2: Uses headRefOid + baseRefName from pass 1 to build a baseRef.compare(headRef: sha) batch query inline — behind_by now accurate
  • Net cost: 2 GraphQL calls per 50 PRs vs the previous 4N REST calls for individual refreshes
  • Removes _incomplete_fields marker
# Pass 1 addition per PR alias
headCommit: commits(last: 1) {
  nodes { commit { statusCheckRollup { state contexts(first: 100) {
    nodes { __typename ... on CheckRun { conclusion status } }
  }}}}
}

# Pass 2 — one batch query for all PRs using inlined head SHAs
pr0: repository(owner: "OWASP-BLT", name: "BLT") {
  ref(qualifiedName: "main") { compare(headRef: "<headRefOid>") { aheadBy } }
}

New repo-level refresh: POST /api/refresh-repo

Refreshes behind_by for all tracked PRs in a repo using 2 GraphQL calls total, independent of PR count. Designed for the "base branch just moved" case (e.g. a PR was merged).

  1. fetch_repo_open_prs() — paginated GraphQL to get all open PRs with headRefOid + baseRefName
  2. fetch_repo_comparison_batch() — single GraphQL batch for all comparisons

Frontend

  • Renames "Refresh All Essential" → "Refresh All PRs" with accurate call count (2 × ⌈n/50⌉)
  • Adds "Refresh Repo Data" button — calls /api/refresh-repo per unique repo; displays 2 × uniqueRepoCount API calls
Original prompt

This section details on the original issue you should resolve

<issue_title>the api calls are still very inefficient lets separate out refreshes that will refresh on each PR and refreshes that will refresh the whole repository</issue_title>
<issue_description>
2026-02-16 17:40:39:110
EST
log
Database: Saved readiness data for PR 9
2026-02-16 17:40:39:059
EST
log
GitHub API: https://api.github.com/repos/OWASP-BLT/BLT/pulls/5604/reviews?per_page=100 | Status: 200 | Rate Limit: 49/60 remaining | Reset: 1771281866
2026-02-16 17:40:39:059
EST
log
Timeline Cache: Stored for OWASP-BLT/BLT/5604
2026-02-16 17:40:39:059
EST
log
Cache: Stored result (memory) for PR 9
2026-02-16 17:40:38:900
EST
log
GitHub API: https://api.github.com/repos/OWASP-BLT/BLT/pulls/5604/comments?per_page=100 | Status: 200 | Rate Limit: 50/60 remaining | Reset: 1771281866
2026-02-16 17:40:38:832
EST
log
GitHub API: https://api.github.com/repos/OWASP-BLT/BLT/issues/5604/comments?per_page=100 | Status: 200 | Rate Limit: 52/60 remaining | Reset: 1771281866
2026-02-16 17:40:38:832
EST
log
GitHub API: https://api.github.com/repos/OWASP-BLT/BLT/pulls/5604/commits?per_page=100 | Status: 200 | Rate Limit: 51/60 remaining | Reset: 1771281866
2026-02-16 17:40:38:654
EST
log
Timeline Cache: MISS for OWASP-BLT/BLT/5604
2026-02-16 17:40:38:631
EST
log
Database: No readiness data found for PR 9
2026-02-16 17:40:38:631
EST
log
Cache: MISS (database) for PR 9
2026-02-16 17:40:38:601
EST
invocation log
GET https://leaf.owaspblt.org/api/prs/9/readiness
2026-02-16 17:40:38:601
EST
log
Rate limit: New IP 2603:7000:8cf0:79a0:d3dd:43f4:c69a:c239 - count: 1
2026-02-16 17:40:38:601
EST
log
Cache: MISS (memory) for PR 9
2026-02-16 17:40:38:492
EST
log
GitHub API: https://api.github.com/rate_limit | Status: 200 | Rate Limit: 53/60 remaining | Reset: 1771281866
2026-02-16 17:40:38:474
EST
invocation log
GET https://leaf.owaspblt.org/api/rate-limit
2026-02-16 17:40:38:361
EST
log
Database: Cleared readiness data for PR 9
2026-02-16 17:40:38:287
EST
log
Compare API success for PR OWASP-BLT/BLT-Leaf#5604
2026-02-16 17:40:38:287
EST
log
PR OWASP-BLT/BLT-Leaf#5604: Compare status=diverged, ahead_by=237, behind_by=13
2026-02-16 17:40:38:272
EST
log
GitHub API: https://api.github.com/repos/OWASP-BLT/BLT/compare/arnavkirti:feature/debug-mode...main | Status: 200 | Rate Limit: 55/60 remaining | Reset: 1771281866
2026-02-16 17:40:37:476
EST
log
GitHub API: https://api.github.com/repos/OWASP-BLT/BLT/commits/fe695d1c2b6528f7d12c1c566c21fbfff20acd6d/check-runs | Status: 200 | Rate Limit: 53/60 remaining | Reset: 1771281866
2026-02-16 17:40:37:416
EST
log
GitHub API: https://api.github.com/repos/OWASP-BLT/BLT/pulls/5604/reviews | Status: 200 | Rate Limit: 54/60 remaining | Reset: 1771281866
2026-02-16 17:40:37:141
EST
log
GitHub API: https://api.github.com/repos/OWASP-BLT/BLT/pulls/5604/files | Status: 200 | Rate Limit: 56/60 remaining | Reset: 1771281866
2026-02-16 17:40:36:986
EST
log
GitHub API: https://api.github.com/repos/OWASP-BLT/BLT/pulls/5604 | Status: 200 | Rate Limit: 57/60 remaining | Reset: 1771281866</issue_description>

<agent_instructions>update to use more efficient queries to update the data please </agent_instructions>

Comments on the Issue (you are @copilot in this section)

@DonnieBLT we have a token now lets see if we can speed this system up

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…heck runs to batch

Co-authored-by: DonnieBLT <128622481+DonnieBLT@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Feb 22, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
blt-leaf 716a88a Commit Preview URL

Branch Preview URL
Feb 22 2026, 08:46 PM

@github-actions github-actions bot added the files-changed: 4 PR changes 4 files label Feb 22, 2026
Copilot AI changed the title [WIP] Separate refresh methods for PR and repository Optimize API refresh: separate PR-level and repo-level updates, add check runs to GraphQL batch Feb 22, 2026
Copilot AI requested a review from DonnieBLT February 22, 2026 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

files-changed: 4 PR changes 4 files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

the api calls are still very inefficient lets separate out refreshes that will refresh on each PR and refreshes that will refresh the whole repository

2 participants