Cache job listings per commit

This commit is contained in:
Rūdolfs Ošiņš
2026-06-04 18:04:33 +02:00
parent 063b7f8d01
commit a6d7d0c1e0
2 changed files with 17 additions and 2 deletions
+2 -2
View File
@@ -5,7 +5,7 @@
import { SvelteSet } from "svelte/reactivity";
import { invoke } from "@app/lib/invoke";
import { cachedListJobs } from "@app/lib/invoke";
import { authorForNodeId, safeHttpUrl } from "@app/lib/utils";
import Button from "@app/components/Button.svelte";
@@ -289,7 +289,7 @@
}
</style>
{#await invoke<Job[]>("list_jobs", { rid, sha: commit }) then jobs}
{#await cachedListJobs(rid, commit) then jobs}
{#if jobs.length > 0}
{@const groups = groupJobs(jobs)}
{@const overallCounts = totalCounts(groups)}
+15
View File
@@ -2,6 +2,7 @@ import type { DiffOptions } from "@bindings/cob/DiffOptions";
import type { Diff } from "@bindings/diff/Diff";
import type { Stats } from "@bindings/diff/Stats";
import type { Commit } from "@bindings/repo/Commit";
import type { Job } from "@bindings/repo/Job";
import type { RepoSummary } from "@bindings/repo/RepoSummary";
import * as tauri from "@tauri-apps/api/core";
@@ -124,6 +125,20 @@ export const cachedRepoCommitCount = cached(
{ max: 5_000 },
);
async function listJobs(rid: string, sha: string): Promise<Job[]> {
return withTestBackend(tauri.invoke, "list_jobs", { rid, sha });
}
// Listing jobs scans every job COB in the repo, so it is slow (hundreds of ms
// to seconds). It is re-requested on every JobCob mount; caching by (rid, sha)
// collapses concurrent identical calls into one in-flight request and reuses
// the result across navigations. A short TTL keeps CI status reasonably fresh.
export const cachedListJobs = cached(
listJobs,
(...[rid, sha]) => `list_jobs:${rid}:${sha}`,
{ max: 200, ttl: 30_000 },
);
async function diffStats(
rid: string,
base: string,