From 9eb071c3f169d03f66bdf65d56023291d6818e93 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sun, 26 Apr 2026 11:53:47 -0700 Subject: [PATCH] perf(plugins): reuse persisted registry fallback read --- src/plugins/plugin-registry.test.ts | 13 +++++++++++++ src/plugins/plugin-registry.ts | 13 ++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/plugins/plugin-registry.test.ts b/src/plugins/plugin-registry.test.ts index 3020411627d..6dda1b905a4 100644 --- a/src/plugins/plugin-registry.test.ts +++ b/src/plugins/plugin-registry.test.ts @@ -309,6 +309,13 @@ describe("plugin registry facade", () => { policyHash: resolveInstalledPluginIndexPolicyHash({ plugins: { entries: { persisted: { enabled: true } } }, }), + installRecords: { + persisted: { + source: "npm", + spec: "persisted-plugin@1.0.0", + installPath: path.join(stateDir, "plugins", "persisted"), + }, + }, }), { stateDir }, ); @@ -329,6 +336,12 @@ describe("plugin registry facade", () => { expect(listPluginRecords({ index: result.snapshot }).map((plugin) => plugin.pluginId)).toEqual([ "demo", ]); + expect(result.snapshot.installRecords).toMatchObject({ + persisted: { + source: "npm", + spec: "persisted-plugin@1.0.0", + }, + }); }); it("falls back to the derived registry when the persisted registry is missing", () => { diff --git a/src/plugins/plugin-registry.ts b/src/plugins/plugin-registry.ts index 207a3e35d96..f674212ae93 100644 --- a/src/plugins/plugin-registry.ts +++ b/src/plugins/plugin-registry.ts @@ -326,12 +326,13 @@ export function loadPluginRegistrySnapshotWithMetadata( const disabledByCaller = params.preferPersisted === false; const disabledByEnv = hasEnvFlag(env, DISABLE_PERSISTED_PLUGIN_REGISTRY_ENV); const persistedReadsEnabled = !disabledByCaller && !disabledByEnv; + let persistedIndex: InstalledPluginIndex | null = null; if (persistedReadsEnabled) { - const persisted = readPersistedInstalledPluginIndexSync(params); - if (persisted) { + persistedIndex = readPersistedInstalledPluginIndexSync(params); + if (persistedIndex) { if ( params.config && - persisted.policyHash !== resolveInstalledPluginIndexPolicyHash(params.config) + persistedIndex.policyHash !== resolveInstalledPluginIndexPolicyHash(params.config) ) { diagnostics.push({ level: "warn", @@ -341,7 +342,7 @@ export function loadPluginRegistrySnapshotWithMetadata( }); } else { return { - snapshot: persisted, + snapshot: persistedIndex, source: "persisted", diagnostics, }; @@ -368,9 +369,7 @@ export function loadPluginRegistrySnapshotWithMetadata( ...params, installRecords: params.installRecords ?? - extractPluginInstallRecordsFromInstalledPluginIndex( - persistedReadsEnabled ? readPersistedInstalledPluginIndexSync(params) : null, - ), + extractPluginInstallRecordsFromInstalledPluginIndex(persistedIndex), }), source: "derived", diagnostics,