From a6d7d0c1e0d5a0fa6e1223393e95e4d714b1cf99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C5=ABdolfs=20O=C5=A1i=C5=86=C5=A1?= Date: Thu, 4 Jun 2026 14:40:50 +0200 Subject: [PATCH] Cache job listings per commit --- src/components/JobCob.svelte | 4 ++-- src/lib/invoke.ts | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/components/JobCob.svelte b/src/components/JobCob.svelte index 4dea0f1d6..b1c6822c8 100644 --- a/src/components/JobCob.svelte +++ b/src/components/JobCob.svelte @@ -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 @@ } -{#await invoke("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)} diff --git a/src/lib/invoke.ts b/src/lib/invoke.ts index f1f9f3e43..286aa9bf5 100644 --- a/src/lib/invoke.ts +++ b/src/lib/invoke.ts @@ -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 { + 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,