perf(secrets): cache channel security artifact lookups

This commit is contained in:
Vincent Koc
2026-04-07 09:04:43 +01:00
parent 1697bb7d23
commit a227d1cc65
2 changed files with 27 additions and 5 deletions

View File

@@ -24,17 +24,31 @@ type BundledChannelContractApi = {
) => UnsupportedSecretRefConfigCandidate[];
};
let bundledChannelDirNameByChannelId: Map<string, string> | null = null;
function getBundledChannelDirName(channelId: string): string | undefined {
if (!bundledChannelDirNameByChannelId) {
bundledChannelDirNameByChannelId = new Map(
loadPluginManifestRegistry({})
.plugins.filter((entry) => entry.origin === "bundled")
.flatMap((entry) =>
entry.channels.map(
(candidateChannelId) => [candidateChannelId, path.basename(entry.rootDir)] as const,
),
),
);
}
return bundledChannelDirNameByChannelId.get(channelId);
}
function loadBundledChannelPublicArtifact(
channelId: string,
artifactBasenames: readonly string[],
): BundledChannelContractApi | undefined {
const record = loadPluginManifestRegistry({})
.plugins.filter((entry) => entry.origin === "bundled")
.find((entry) => entry.channels.includes(channelId));
if (!record) {
const dirName = getBundledChannelDirName(channelId);
if (!dirName) {
return undefined;
}
const dirName = path.basename(record.rootDir);
for (const artifactBasename of artifactBasenames) {
try {

View File

@@ -1,3 +1,5 @@
import fs from "node:fs";
import path from "node:path";
import { loadPluginManifestRegistry } from "../plugins/manifest-registry.js";
import { isRecord } from "../utils.js";
import { loadBundledChannelSecurityContractApi } from "./channel-contract-api.js";
@@ -15,6 +17,12 @@ function listBundledChannelIds(): string[] {
...new Set(
loadPluginManifestRegistry({})
.plugins.filter((entry) => entry.origin === "bundled")
.filter((entry) => {
return (
fs.existsSync(path.join(entry.rootDir, "security-contract-api.ts")) ||
fs.existsSync(path.join(entry.rootDir, "security-contract-api.js"))
);
})
.flatMap((entry) => entry.channels),
),
].toSorted((left, right) => left.localeCompare(right));