perf(plugins): reuse persisted registry fallback read

This commit is contained in:
Vincent Koc
2026-04-26 11:53:47 -07:00
parent 522eedc754
commit 9eb071c3f1
2 changed files with 19 additions and 7 deletions

View File

@@ -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", () => {

View File

@@ -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,