mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-21 22:21:33 +00:00
perf(plugins): cache shared boundary freshness scans
This commit is contained in:
@@ -233,12 +233,16 @@ function collectOldestMtime(paths) {
|
||||
export function isBoundaryCompileFresh(extensionId, params = {}) {
|
||||
const rootDir = params.rootDir ?? repoRoot;
|
||||
const extensionRoot = resolve(rootDir, "extensions", extensionId);
|
||||
const newestInputMtimeMs = Math.max(
|
||||
collectNewestMtime(extensionRoot, { includeFile: isRelevantCompileInput }),
|
||||
collectNewestMtime(resolve(rootDir, "extensions", extensionId, "tsconfig.json")),
|
||||
collectNewestMtime(resolve(rootDir, "dist/plugin-sdk")),
|
||||
collectNewestMtime(resolve(rootDir, "packages/plugin-sdk/dist")),
|
||||
);
|
||||
const extensionNewestInputMtimeMs =
|
||||
params.extensionNewestInputMtimeMs ??
|
||||
collectNewestMtime(extensionRoot, { includeFile: isRelevantCompileInput });
|
||||
const sharedNewestInputMtimeMs =
|
||||
params.sharedNewestInputMtimeMs ??
|
||||
Math.max(
|
||||
collectNewestMtime(resolve(rootDir, "dist/plugin-sdk")),
|
||||
collectNewestMtime(resolve(rootDir, "packages/plugin-sdk/dist")),
|
||||
);
|
||||
const newestInputMtimeMs = Math.max(extensionNewestInputMtimeMs, sharedNewestInputMtimeMs);
|
||||
const oldestOutputMtimeMs = collectOldestMtime([
|
||||
resolveBoundaryTsStampPath(extensionId, rootDir),
|
||||
]);
|
||||
@@ -550,14 +554,29 @@ async function runCompileCheck(extensionIds) {
|
||||
const prepElapsedMs = Date.now() - prepStartedAt;
|
||||
const concurrency = resolveCompileConcurrency();
|
||||
const verboseFreshLogs = process.env.OPENCLAW_EXTENSION_BOUNDARY_VERBOSE_FRESH === "1";
|
||||
const sharedNewestInputMtimeMs = Math.max(
|
||||
collectNewestMtime(resolve(repoRoot, "dist/plugin-sdk")),
|
||||
collectNewestMtime(resolve(repoRoot, "packages/plugin-sdk/dist")),
|
||||
);
|
||||
process.stdout.write(`compile concurrency ${concurrency}\n`);
|
||||
const compileStartedAt = Date.now();
|
||||
let skippedCompileCount = 0;
|
||||
const steps = extensionIds
|
||||
.map((extensionId, index) => {
|
||||
const tsBuildInfoPath = resolveBoundaryTsBuildInfoPath(extensionId);
|
||||
const extensionNewestInputMtimeMs = collectNewestMtime(
|
||||
resolve(repoRoot, "extensions", extensionId),
|
||||
{
|
||||
includeFile: isRelevantCompileInput,
|
||||
},
|
||||
);
|
||||
mkdirSync(dirname(tsBuildInfoPath), { recursive: true });
|
||||
if (isBoundaryCompileFresh(extensionId)) {
|
||||
if (
|
||||
isBoundaryCompileFresh(extensionId, {
|
||||
extensionNewestInputMtimeMs,
|
||||
sharedNewestInputMtimeMs,
|
||||
})
|
||||
) {
|
||||
skippedCompileCount += 1;
|
||||
if (verboseFreshLogs) {
|
||||
process.stdout.write(
|
||||
|
||||
@@ -262,6 +262,36 @@ describe("check-extension-package-tsc-boundary", () => {
|
||||
expect(isBoundaryCompileFresh("demo", { rootDir })).toBe(false);
|
||||
});
|
||||
|
||||
it("accepts cached input mtimes for freshness checks", () => {
|
||||
const { rootDir, extensionRoot } = createTempExtensionRoot();
|
||||
const extensionSourcePath = path.join(extensionRoot, "index.ts");
|
||||
const stampPath = path.join(extensionRoot, "dist", ".boundary-tsc.stamp");
|
||||
|
||||
fs.mkdirSync(path.dirname(extensionSourcePath), { recursive: true });
|
||||
fs.mkdirSync(path.dirname(stampPath), { recursive: true });
|
||||
fs.writeFileSync(extensionSourcePath, "export const demo = 1;\n", "utf8");
|
||||
fs.writeFileSync(stampPath, "ok\n", "utf8");
|
||||
|
||||
fs.utimesSync(extensionSourcePath, new Date(1_000), new Date(1_000));
|
||||
fs.utimesSync(stampPath, new Date(3_000), new Date(3_000));
|
||||
|
||||
expect(
|
||||
isBoundaryCompileFresh("demo", {
|
||||
rootDir,
|
||||
extensionNewestInputMtimeMs: 1_000,
|
||||
sharedNewestInputMtimeMs: 2_000,
|
||||
}),
|
||||
).toBe(true);
|
||||
|
||||
expect(
|
||||
isBoundaryCompileFresh("demo", {
|
||||
rootDir,
|
||||
extensionNewestInputMtimeMs: 1_000,
|
||||
sharedNewestInputMtimeMs: 4_000,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("keeps full failure output on the thrown error for canary detection", async () => {
|
||||
await expect(
|
||||
runNodeStepAsync(
|
||||
|
||||
Reference in New Issue
Block a user