Skip to content

Commit 6157933

Browse files
committed
perf(config): skip cold runtime refresh on one-shot writes
1 parent bd20a92 commit 6157933

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

‎src/commands/gateway-install-token.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,10 @@ describe("resolveGatewayInstallToken", () => {
199199
},
200200
},
201201
}),
202-
expect.objectContaining({ baseSnapshot: expect.any(Object) }),
202+
expect.objectContaining({
203+
baseSnapshot: expect.any(Object),
204+
skipRuntimeSnapshotRefresh: true,
205+
}),
203206
);
204207
});
205208

‎src/commands/gateway-install-token.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ async function maybePersistAutoGeneratedGatewayInstallToken(params: {
8080
baseSnapshot: snapshot,
8181
...prepared.writeOptions,
8282
...params.configWriteOptions,
83+
skipRuntimeSnapshotRefresh: true,
8384
},
8485
);
8586
return params.token;

‎src/config/io.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ import {
7979
registerRuntimeConfigWriteListener,
8080
resetConfigRuntimeState as resetConfigRuntimeStateState,
8181
setRuntimeConfigSnapshot as setRuntimeConfigSnapshotState,
82+
getRuntimeConfigSnapshotRefreshHandler as getRuntimeConfigSnapshotRefreshHandlerState,
8283
setRuntimeConfigSnapshotRefreshHandler as setRuntimeConfigSnapshotRefreshHandlerState,
8384
type RuntimeConfigWriteNotification,
8485
} from "./runtime-snapshot.js";
@@ -154,6 +155,11 @@ export type ConfigWriteOptions = {
154155
* Avoids rereading the full config just to prepare an immediate write.
155156
*/
156157
baseSnapshot?: ConfigFileSnapshot;
158+
/**
159+
* Internal one-shot CLI fast path. When no runtime snapshot is active, skip
160+
* the post-write runtime snapshot refresh/reload tail entirely.
161+
*/
162+
skipRuntimeSnapshotRefresh?: boolean;
157163
};
158164

159165
export type ReadConfigFileSnapshotForWriteResult = {
@@ -1799,7 +1805,15 @@ export async function writeConfigFile(
17991805
envSnapshotForRestore: options.envSnapshotForRestore,
18001806
}),
18011807
unsetPaths: options.unsetPaths,
1808+
skipRuntimeSnapshotRefresh: options.skipRuntimeSnapshotRefresh,
18021809
});
1810+
if (
1811+
options.skipRuntimeSnapshotRefresh &&
1812+
!hadRuntimeSnapshot &&
1813+
!getRuntimeConfigSnapshotRefreshHandlerState()
1814+
) {
1815+
return;
1816+
}
18031817
const notifyCommittedWrite = () => {
18041818
const currentRuntimeConfig = getRuntimeConfigSnapshotState();
18051819
if (!currentRuntimeConfig) {

0 commit comments

Comments
 (0)