Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): skip periodic checks for disabled providers #18851

Mergedsaphid(GitHub profile, opens in a new tab)merged 6 commits intomain fromrefs/pull/18851/headmerged by juliusmarminge View on GitHub

Showing 2 changed files with 58 additions and 0 deletions.

x
0 of 2 viewed, 2 left
53 additions and 0 deletionspackages/provider-core/src/server/managedProvider.test.tsModified
View file
@@ -293,6 +293,59 @@
).pipe(Effect.provide(Layer.mergeAll(layerNeverRunTest, TestClock.layer()))),
​
+ it.effect("skips periodic checks while disabled and resumes them once enabled", () =>
+ Effect.scoped(
+ Effect.gen(function* () {
+ const settingsRef = yield* Ref.make<TestSettings>({ enabled: false });
+ const settingsChanges = yield* PubSub.unbounded<TestSettings>();
+ const checkCalls = yield* Ref.make(0);
+ const releaseInitialCheck = yield* Deferred.make<void>();
+ const updates = yield* Queue.unbounded<ServerProvider>();
+ const provider = yield* makeManagedServerProvider<TestSettings>({
+ resolveMaintenance: () => Effect.succeed(maintenanceCapabilities),
+ getSettings: Ref.get(settingsRef),
+ streamSettings: Stream.fromPubSub(settingsChanges),
+ haveSettingsChanged: (previous, next) => previous.enabled !== next.enabled,
+ initialSnapshot: () => Effect.succeed({ ...initialSnapshot, enabled: false }),
+ checkProvider: Ref.updateAndGet(checkCalls, (count) => count + 1).pipe(
+ Effect.tap((count) =>
+ count === 1 ? Deferred.await(releaseInitialCheck) : Effect.void,
+ ),
+ Effect.andThen(Ref.get(settingsRef)),
+ Effect.map(({ enabled }) => ({ ...refreshedSnapshot, enabled })),
+ ),
+ refreshInterval: "5 minutes",
+ });
+ yield* provider.streamChanges.pipe(
+ Stream.runForEach((snapshot) => Queue.offer(updates, snapshot)),
+ Effect.forkScoped,