Skip to content

Commit 668af67

Browse files
committed
refactor(server): retain settings within the disk loader
1 parent d7cc345 commit 668af67

1 file changed

Lines changed: 15 additions & 22 deletions

File tree

‎apps/server/src/serverSettings.ts‎

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -797,33 +797,26 @@ const make = Effect.gen(function* () {
797797
yield* secretStore.remove(move.from).pipe(Effect.ignore);
798798
}
799799
}
800+
if (Option.isNone(parseFailure)) {
801+
yield* Ref.set(lastGoodSettingsRef, Option.some(migrated));
802+
} else {
803+
const lastGood = yield* Ref.get(lastGoodSettingsRef);
804+
if (Option.isSome(lastGood)) {
805+
return {
806+
settings: { ...lastGood.value, continueThreadsAfterServerUpdate: false },
807+
parseFailure,
808+
fromPublishedSave,
809+
};
810+
}
811+
}
800812
return { settings: migrated, parseFailure, fromPublishedSave };
801813
});
802814

803-
// A file caught mid-write or left invalid keeps the settings that last loaded instead of
804-
// resetting them to defaults, also for readers that join a reload. Its parse failure still
805-
// blocks saves, and it still never resumes threads, as at startup: the unreadable file may
806-
// hold an opt-out.
807-
const loadKeepingLastGoodSettings = Effect.gen(function* () {
808-
const loaded = yield* loadSettingsFromDisk;
809-
if (Option.isNone(loaded.parseFailure)) {
810-
yield* Ref.set(lastGoodSettingsRef, Option.some(loaded.settings));
811-
return loaded;
812-
}
813-
const lastGood = yield* Ref.get(lastGoodSettingsRef);
814-
return Option.isSome(lastGood)
815-
? { ...loaded, settings: { ...lastGood.value, continueThreadsAfterServerUpdate: false } }
816-
: loaded;
815+
const settingsCache = yield* Cache.makeWith((_key: typeof cacheKey) => loadSettingsFromDisk, {
816+
capacity: 1,
817+
timeToLive: (exit) => (Exit.isSuccess(exit) ? Duration.infinity : Duration.zero),
817818
});
818819

819-
const settingsCache = yield* Cache.makeWith(
820-
(_key: typeof cacheKey) => loadKeepingLastGoodSettings,
821-
{
822-
capacity: 1,
823-
timeToLive: (exit) => (Exit.isSuccess(exit) ? Duration.infinity : Duration.zero),
824-
},
825-
);
826-
827820
const getSettingsFromCache = Cache.get(settingsCache, cacheKey).pipe(
828821
Effect.map((loaded) => loaded.settings),
829822
);

0 commit comments

Comments
 (0)