fix(insight): lazily initialize route preferences

This commit is contained in:
digua committed 2026-08-11 10:38:05 +08:00
1 parent a2e66d07da
commit 502b781024
1 file changed
+5 -2
@@ -17,8 +17,11 @@ type GlobalInsightRouteContext = Pick<
Pick<ServiceRouteContext, 'globalInsightService' | 'timeInvestmentService' | 'preferencesManager'>
export function registerGlobalInsightRoutes(server: FastifyInstance, ctx: GlobalInsightRouteContext): void {
const preferences = ctx.preferencesManager ?? new PreferencesManager(ctx.pathProvider.getSystemDir())
const getExcludedSessionIds = () => preferences.load().ownerExcludedSessionIds
let preferences = ctx.preferencesManager
const getExcludedSessionIds = () => {
preferences ??= new PreferencesManager(ctx.pathProvider.getSystemDir())
return preferences.load().ownerExcludedSessionIds
}
const service =
ctx.globalInsightService ??
createGlobalInsightService({