mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 00:30:21 +00:00
perf(secrets): cache channel security artifact lookups
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user