@@ -4,11 +4,11 @@ import {
44 Outlet ,
55 useLoaderData ,
66} from 'react-router'
7- import * as prismaRuntime from '@prisma/client/runtime/client'
87import { GeneralErrorBoundary } from '#app/components/error-boundary.tsx'
98import { requireUserId } from '#app/utils/auth.server.js'
109import { CronParseError , getScheduleWindow } from '#app/utils/cron.server.ts'
1110import { prisma } from '#app/utils/db.server.ts'
11+ import { getunsentmessagecounts } from '#app/utils/prisma-generated.server/sql.ts'
1212import {
1313 NEXT_SCHEDULE_SENTINEL_DATE ,
1414 PREV_SCHEDULE_SENTINEL_DATE ,
@@ -38,23 +38,6 @@ function formatScheduleDisplay(date: Date, timeZone: string) {
3838const DEFAULT_RECIPIENTS_PAGE_SIZE = 200
3939const MAX_RECIPIENTS_PAGE_SIZE = 1000
4040
41- type UnsentMessageCountRow = {
42- recipientId : string
43- unsentCount : number | null
44- }
45-
46- const getUnsentMessageCounts = prismaRuntime . makeTypedQueryFactory (
47- `SELECT
48- recipientId,
49- CAST(COUNT(*) AS INTEGER) AS unsentCount
50- FROM Message INDEXED BY message_unsent_by_recipient
51- WHERE sentAt IS NULL
52- AND recipientId IN (SELECT value FROM json_each($1))
53- GROUP BY recipientId;` ,
54- ) as (
55- recipientIdsJson : string ,
56- ) => prismaRuntime . TypedSql < [ recipientIdsJson : string ] , UnsentMessageCountRow >
57-
5841function parsePageSize ( value : string | null ) {
5942 const parsed = Number ( value ?? DEFAULT_RECIPIENTS_PAGE_SIZE )
6043 if ( ! Number . isFinite ( parsed ) ) return DEFAULT_RECIPIENTS_PAGE_SIZE
@@ -88,7 +71,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
8871 const recipientIds = recipients . map ( ( recipient ) => recipient . id )
8972 const messageCounts = recipientIds . length
9073 ? await prisma . $queryRawTyped (
91- getUnsentMessageCounts ( JSON . stringify ( recipientIds ) ) ,
74+ getunsentmessagecounts ( JSON . stringify ( recipientIds ) ) ,
9275 )
9376 : [ ]
9477 const messageCountByRecipientId = new Map (
0 commit comments