diff --git a/src/lib/rollups/medication-compliance-rollups.ts b/src/lib/rollups/medication-compliance-rollups.ts index 6184361c3..d67d9c033 100644 --- a/src/lib/rollups/medication-compliance-rollups.ts +++ b/src/lib/rollups/medication-compliance-rollups.ts @@ -16,8 +16,6 @@ * * Audit anchor: `.planning/round-v1438-perf-analysis.md` §2.5 + §5 P4. */ -import type { Prisma } from "@/generated/prisma/client"; - import { prisma } from "@/lib/db"; import { getGlobalBoss } from "@/lib/jobs/boss-instance"; import { annotate } from "@/lib/logging/context"; @@ -58,14 +56,6 @@ export interface ComplianceBucket { taken: number; } -/** - * Prisma client surface the helpers accept. Either the regular - * `prisma` singleton or a `$transaction(tx)` argument — both expose - * the `medicationIntakeEvent.findMany` + `medicationComplianceRollup.*` - * methods we touch. - */ -type PrismaLike = typeof prisma | Prisma.TransactionClient; - /** * UTC offset (in minutes) of `tz` at the given instant. Positive east * of UTC. Honours DST via `Intl.DateTimeFormat`. @@ -147,18 +137,14 @@ export function dayKeyForScheduledFor( * so the read path returns the trailing-window zero-default rather * than a stale stub. * - * `tx` accepts the `prisma.$transaction(tx)` client argument when the - * parent write is transactional — passing the transaction client keeps - * the rollup write inside the same transactional boundary. */ export async function recomputeMedicationComplianceForDay( userId: string, medicationId: string, dayKey: string, tz: string | null | undefined, - tx?: PrismaLike, ): Promise { - const client = (tx ?? prisma) as PrismaLike; + const client = prisma; const safeTz = safeTimezone(tz); const start = startOfDayUtcInTz(dayKey, safeTz); const end = new Date(start.getTime() + 86_400_000); @@ -247,7 +233,6 @@ export async function recomputeMedicationComplianceForEvent(input: { medicationId: string; scheduledFor: Date; tz: string | null | undefined; - tx?: PrismaLike; }): Promise { const dayKey = dayKeyForScheduledFor(input.scheduledFor, input.tz); try { @@ -256,7 +241,6 @@ export async function recomputeMedicationComplianceForEvent(input: { input.medicationId, dayKey, input.tz, - input.tx, ); } catch (err) { const message = err instanceof Error ? err.message : String(err); diff --git a/src/lib/rollups/mood-rollups.ts b/src/lib/rollups/mood-rollups.ts index bb7df0069..3100340e9 100644 --- a/src/lib/rollups/mood-rollups.ts +++ b/src/lib/rollups/mood-rollups.ts @@ -166,17 +166,12 @@ export async function recomputeUserMoodRollups( * * Scoped to the affected `(userId, day)` tuple — cheap, and avoids * invalidating buckets that haven't changed. - * - * Pass `tx` when called from inside a `prisma.$transaction` block so - * the rollup write commits atomically with the parent mutation. - * Otherwise the global `prisma` client is used. */ export async function recomputeMoodBucketsForEntry( userId: string, moodLoggedAt: Date, - tx?: PrismaTxOrClient, ): Promise { - const client = tx ?? prisma; + const client = prisma; // DAY pass — synchronous. v1.4.39 hotfix (QA F-H-02): one atomic SQL // statement re-aggregates inside the upsert subquery, closing the // race window where two concurrent writes for the same (user, day)