perf: bound request work and resource usage (#866)

* perf: bound request work and resource usage

* fix: address performance review regressions

* fix: guard content expiration and dashboard state

* fix: tolerate cache outages and retire derived paths

* fix: revalidate expiration claims and status pagination

* fix: retry interrupted repository metadata cleanup

* fix: retire obsolete content cache storage

* fix: activate tree metadata and recheck expiration claims

* fix: fence cache publication across expiration

* fix: recover staged trees and enforce cache lifecycle cleanup

* fix: prune expired transforms during database outages

* fix: finish conference removals and reload expiration candidates
This commit is contained in:
Thomas Durieux authored and GitHub committed 2026-10-08 03:38:19 +01:00
1 parent 32722169a2
commit 6434337923
74 files changed
+4752 -553

No files matched your search

+17 -22
View File
@@ -1,3 +1,4 @@
import { AsyncCache } from "../../core/async-cache";
import * as os from "os";
import { execSync } from "child_process";
import { Queue, JobType } from "bullmq";
@@ -342,18 +343,11 @@ router.get("/queues/metrics", dashboardCache, async (req, res) => {
}
});
const queuesCache = new Map<string, { data: unknown; ts: number }>();
const QUEUES_CACHE_TTL = 10_000;
const queuesCache = new AsyncCache<{ queues: unknown; selectedQueue: string; jobs: Record<string, unknown>[] }>(10_000, 3);
router.get("/queues", dashboardCache, async (req, res) => {
const search = req.query.search ? String(req.query.search).toLowerCase() : "";
const queueName = req.query.queue ? String(req.query.queue) : "";
const cacheKey = `${queueName}|${search}`;
const cached = queuesCache.get(cacheKey);
if (cached && Date.now() - cached.ts < QUEUES_CACHE_TTL) {
return res.json(cached.data);
}
const allQueues: { key: string; label: string; queue: Queue }[] = [
{ key: "download", label: "Download", queue: downloadQueue },
{ key: "remove", label: "Remove", queue: removeQueue },
@@ -365,6 +359,7 @@ router.get("/queues", dashboardCache, async (req, res) => {
: allQueues[0];
const targetQueue = target ? target.queue : downloadQueue;
const data = await queuesCache.get(target?.key || "download", async () => {
const [statsResults, ...jobsByState] = await Promise.all([
Promise.all(
allQueues.map(async (q) => ({
@@ -385,6 +380,19 @@ router.get("/queues", dashboardCache, async (req, res) => {
}),
]);
const allJobs = (jobsByState as Record<string, unknown>[][]).flat();
const stateOrder: Record<string, number> = {
active: 0, waiting: 1, delayed: 2, failed: 3, completed: 4,
};
allJobs.sort((a, b) => (stateOrder[a._state as string] ?? 9) - (stateOrder[b._state as string] ?? 9));
return {
queues: statsResults,
selectedQueue: target?.key || "download",
jobs: allJobs,
};
});
const matches = (job: { id?: string | undefined; name?: string }) => {
if (!search) return true;
return (
@@ -392,20 +400,7 @@ router.get("/queues", dashboardCache, async (req, res) => {
(job.name || "").toLowerCase().includes(search)
);
};
const allJobs = (jobsByState as Record<string, unknown>[][]).flat().filter(matches);
const stateOrder: Record<string, number> = {
active: 0, waiting: 1, delayed: 2, failed: 3, completed: 4,
};
allJobs.sort((a, b) => (stateOrder[a._state as string] ?? 9) - (stateOrder[b._state as string] ?? 9));
const data = {
queues: statsResults,
selectedQueue: target?.key || "download",
jobs: allJobs,
};
queuesCache.set(cacheKey, { data, ts: Date.now() });
res.json(data);
res.json({ ...data, jobs: data.jobs.filter(matches) });
});
// Errors captured by the logger sink. Server-paginated to avoid pulling