From 1c0c1948204265b0b2058f260b65c50ce516a601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Tue, 7 Jul 2026 19:31:41 +0200 Subject: [PATCH] fix(documents): scope the content-index gauge to live documents The usage endpoint counted every DocumentContentIndex row for the user, including those whose parent document has been soft-deleted (the index row survives until the hard purge). Against totalCount, which filters live documents, the gauge could read past 100 %. Scope the indexed count to live documents so coverage never exceeds the corpus. Also drop a redundant identical-branch ternary in the per-document content-index status row. --- src/app/api/documents/inbound/usage/route.ts | 7 ++++++- src/components/documents/document-ai-panels.tsx | 7 +------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/app/api/documents/inbound/usage/route.ts b/src/app/api/documents/inbound/usage/route.ts index 4e0f45b89..a81fbe207 100644 --- a/src/app/api/documents/inbound/usage/route.ts +++ b/src/app/api/documents/inbound/usage/route.ts @@ -49,7 +49,12 @@ export const GET = apiHandler(async () => { // offers what the endpoint would 422. resolveOcrCapability(user.id), // Content-index coverage: how many live documents are indexed … - prisma.documentContentIndex.count({ where: { userId: user.id } }), + // Scope the count to LIVE documents: a soft-deleted document keeps its + // index row (cascade fires on hard purge only), so an unscoped count + // would drift above `totalCount` and read the gauge past 100 %. + prisma.documentContentIndex.count({ + where: { userId: user.id, document: { deletedAt: null } }, + }), // … out of how many live documents there are. prisma.inboundDocument.count({ where: { userId: user.id, deletedAt: null }, diff --git a/src/components/documents/document-ai-panels.tsx b/src/components/documents/document-ai-panels.tsx index d24b0b1f2..e0a6b728b 100644 --- a/src/components/documents/document-ai-panels.tsx +++ b/src/components/documents/document-ai-panels.tsx @@ -298,12 +298,7 @@ export function ContentIndexStatus({ data-slot="content-index-status" className="flex items-center justify-between gap-2" > -

+

{hasContentIndex ? t("documents.contentIndex.searchable")