mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 14:20:42 +08:00
Cache job listings per commit
This commit is contained in:
@@ -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)}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user