diff --git a/apps/web/app/(app)/[emailAccountId]/reply-zero/fetch-trackers.ts b/apps/web/app/(app)/[emailAccountId]/reply-zero/fetch-trackers.ts index ed6ba3d12..da8a0bb16 100644 --- a/apps/web/app/(app)/[emailAccountId]/reply-zero/fetch-trackers.ts +++ b/apps/web/app/(app)/[emailAccountId]/reply-zero/fetch-trackers.ts @@ -25,13 +25,16 @@ export async function getPaginatedThreadTrackers({ const [trackers, total] = await Promise.all([ prisma.$queryRaw` - SELECT DISTINCT ON ("threadId") * - FROM "ThreadTracker" - WHERE "emailAccountId" = ${emailAccountId} - AND "resolved" = false - AND "type" = ${type}::text::"ThreadTrackerType" - ${dateClause} - ORDER BY "threadId", "createdAt" DESC + SELECT * FROM ( + SELECT DISTINCT ON ("threadId") * + FROM "ThreadTracker" + WHERE "emailAccountId" = ${emailAccountId} + AND "resolved" = false + AND "type" = ${type}::text::"ThreadTrackerType" + ${dateClause} + ORDER BY "threadId", "createdAt" DESC + ) AS distinct_threads + ORDER BY "createdAt" DESC LIMIT ${PAGE_SIZE} OFFSET ${skip} `,