From 35b4e75a53bd461f06b0e4a061911ade777b1f71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Wed, 11 Nov 2026 00:52:40 +0100 Subject: [PATCH] refactor(reminders): share the satisfiable select with the Telegram button The select is checked against SatisfiableReminder, so a column the reschedule needs cannot be left out of a narrowed read again, and the handler is back under its size baseline. --- src/lib/measurement-reminders/satisfy.ts | 15 +++++++++++++++ src/lib/telegram-webhook-handlers.ts | 17 +++++------------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/lib/measurement-reminders/satisfy.ts b/src/lib/measurement-reminders/satisfy.ts index ec19854d2..6705187c8 100644 --- a/src/lib/measurement-reminders/satisfy.ts +++ b/src/lib/measurement-reminders/satisfy.ts @@ -81,6 +81,21 @@ export interface SatisfiableReminder { endsOn: Date | null; } +/** The select a caller that narrows its read gives a satisfiable row. */ +export const SATISFIABLE_REMINDER_SELECT = { + id: true, + userId: true, + intervalDays: true, + rrule: true, + anchorDate: true, + notifyHour: true, + nextDueAt: true, + lastSatisfiedAt: true, + lastSkippedAt: true, + createdAt: true, + endsOn: true, +} as const satisfies Record; + export interface SatisfyResult { /** True when the reminder was advanced; false when the event was older * than (or equal to) the existing `lastSatisfiedAt` (forward-only diff --git a/src/lib/telegram-webhook-handlers.ts b/src/lib/telegram-webhook-handlers.ts index 6f7242d7a..b1f2e920e 100644 --- a/src/lib/telegram-webhook-handlers.ts +++ b/src/lib/telegram-webhook-handlers.ts @@ -29,7 +29,10 @@ import { attachTelegramMoodNote, } from "@/lib/mood/create-from-telegram"; import { scheduleTelegramAutoDelete } from "@/lib/telegram-cleanup"; -import { satisfyReminder } from "@/lib/measurement-reminders/satisfy"; +import { + SATISFIABLE_REMINDER_SELECT, + satisfyReminder, +} from "@/lib/measurement-reminders/satisfy"; import { isTelegramCapturableType, logTelegramMeasurement, @@ -865,19 +868,9 @@ export async function handleCallback(update: TelegramUpdate) { origin: { not: "ENCOUNTER" }, }, select: { - id: true, - userId: true, + ...SATISFIABLE_REMINDER_SELECT, // v1.19.2 — the target metric; drives the optional numeric capture. measurementType: true, - intervalDays: true, - rrule: true, - anchorDate: true, - notifyHour: true, - nextDueAt: true, - lastSatisfiedAt: true, - lastSkippedAt: true, - createdAt: true, - endsOn: true, }, }); if (!reminder) {