Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.
| Last commits read trees two dozen commits at a time, and the file list waits at most 3 s for them | 1 | /** |
| 2 | * Each entry's last commit for the file list, waited on only so long. An | |
| 3 | * answer not yet kept walks history, which can take seconds on a large or | |
| 4 | * busy repository; the page goes out without it then, the column empty, | |
| 5 | * while the walk finishes in the background (waitUntil) so the next view | |
| 6 | * has it from the cache. The page's stream never waits on it past its own | |
| 7 | * timeout. | |
| 8 | */ | |
| 9 | import { waitUntil } from "cloudflare:workers"; | |
| 10 | ||
| 11 | import type { LastCommits, RepoPath, Viewer } from "@g1t/contracts"; | |
| 12 | ||
| 13 | import { repos } from "./services.server"; | |
| 14 | ||
| 15 | /** How long the page waits for the column. */ | |
| 16 | const WAIT_MS = 3_000; | |
| 17 | ||
| 18 | export function lastCommitsFor(path: RepoPath, viewer: Viewer, ref: string | null, treePath: string): Promise<LastCommits | null> { | |
| 19 | const walk = repos | |
| 20 | .lastCommits(path, viewer, ref, treePath) | |
| 21 | .then((found) => (found.ok ? found.value : null)) | |
| 22 | .catch(() => null); | |
| 23 | waitUntil(walk); | |
| 24 | return Promise.race([walk, new Promise<null>((resolve) => setTimeout(() => resolve(null), WAIT_MS))]); | |
| 25 | } |