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.
This commit is contained in:
Marc-André Bombeck committed 2026-07-07 19:31:41 +02:00
1 parent 2319988a96
commit 1c0c194820
2 files changed
+7 -7

No files matched your search

+6 -1
View File
@@ -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 },
@@ -298,12 +298,7 @@ export function ContentIndexStatus({
data-slot="content-index-status"
className="flex items-center justify-between gap-2"
>
<p
className={cn(
"inline-flex items-center gap-1.5 text-xs",
hasContentIndex ? "text-muted-foreground" : "text-muted-foreground",
)}
>
<p className="text-muted-foreground inline-flex items-center gap-1.5 text-xs">
<ScanSearch className="size-3.5 shrink-0" aria-hidden />
{hasContentIndex
? t("documents.contentIndex.searchable")