perf(auth): read the operator settings once per request

An app boot's /api/auth/me read the AppSettings singleton six times, each
reader with its own few columns: the MFA policy, the Assistant switches,
the module availability, the provider presence, the AI usage bounds and
the reasoning controls. They now take their columns from one read,
memoised for the request and read afresh inside a background job like the
readers themselves. No answer changes.
This commit is contained in:
Marc-André Bombeck committed 2026-10-22 07:25:00 +02:00
1 parent e00943ff7f
commit f8a88d1361
7 files changed
+68 -46

No files matched your search

+2 -5
View File
@@ -36,7 +36,7 @@
* 0343 folded the blob's `coach` key into the switch and removed it, and a
* `coach` key that still turns up in the blob is ignored.
*/
import { prisma } from "@/lib/db";
import { readOperatorRow } from "@/lib/settings/operator-row";
import { getAssistantFlags } from "@/lib/feature-flags";
import { getEvent } from "@/lib/logging/context";
import { memoizePerRequest } from "@/lib/request-cache";
@@ -84,10 +84,7 @@ export function resolveOperatorAvailability(
/** The raw availability blob; a read error reads as "nothing disabled". */
async function loadAvailabilityBlob(): Promise<unknown> {
try {
const settings = await prisma.appSettings.findUnique({
where: { id: "singleton" },
select: { moduleAvailabilityJson: true },
});
const settings = await readOperatorRow();
return settings?.moduleAvailabilityJson ?? null;
} catch {
getEvent()?.addWarning(