Skip to content

Commit bc357a4

Browse files
authored
Add Cache-Control to the commit API route (#8580)
Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.14.0) (oldest at bottom): * #8584 * #8582 * __->__ #8580 * #8579 * #8578 * #8576 **Impact:** HUD commit page consumers (CDN-cached reads) **Risk:** low ## What Set a short-TTL `Cache-Control` header (`s-maxage=60, stale-while-revalidate=240`) on the `/api/[repoOwner]/[repoName]/commit/[sha]` endpoint, which previously sent no caching headers. ## Why The commit endpoint calls into GitHub via `fetchCommit`, and every repeat view hit the origin, adding to the shared PyTorchBot installation's rate-limit budget. Caching at the CDN collapses repeat views of the same sha to at most one origin call per minute. The TTL is kept short because the response mixes immutable commit metadata with live CI job data that must stay fresh. Signed-off-by: Jean Schmidt <contato@jschmidt.me>
1 parent 8fd31c1 commit bc357a4

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

  • torchci/pages/api/[repoOwner]/[repoName]/commit

torchci/pages/api/[repoOwner]/[repoName]/commit/[sha].ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@ export default async function handler(
1919
) {
2020
const workflowId = parseInt(req.query.workflowId as string, 10) || 0;
2121
const runAttempt = parseInt(req.query.runAttempt as string, 10) || 0;
22-
res
23-
.status(200)
24-
.json(
25-
await fetchCommit(
26-
req.query.repoOwner as string,
27-
req.query.repoName as string,
28-
req.query.sha as string,
29-
workflowId,
30-
runAttempt
31-
)
32-
);
22+
const data = await fetchCommit(
23+
req.query.repoOwner as string,
24+
req.query.repoName as string,
25+
req.query.sha as string,
26+
workflowId,
27+
runAttempt
28+
);
29+
// Short TTL because the response bundles live CI job data with the immutable commit metadata.
30+
res.setHeader("Cache-Control", "s-maxage=60, stale-while-revalidate=240");
31+
res.status(200).json(data);
3332
}

0 commit comments

Comments
 (0)