perf(documents): move density aggregation into SQL when documents > 50k #481
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
The
/api/documents/densityendpoint (issue #385) currently groups by month in JVM memory:This loads every matching
Documentrow (with eager joins for sender/receivers/tags) and groups in Java. Acceptable today (~5k rows, <50ms). The trade-off and threshold are documented inline:This issue exists so the threshold lives outside the code comment, where comments age into invisibility (per @Markus's PR #478 review and @Elicit OQ-385-1).
Acceptance criteria
GROUP BY TO_CHAR(meta_date, 'YYYY-MM')(ordate_trunc) query.buildSearchSpecfilters (sender, receiver, tag, status, FTS, tagOp); the implementation may take a parallel native-query /EntityManager.createNativeQuerypath that mirrors the Specification predicates.idx_documents_meta_dateindex that was dropped in commit360db1aeonce SQL aggregation lands — at that scale the index pays.Triggering signal
Re-evaluate when
SELECT COUNT(*) FROM documents > 50_000or when p95 ofGET /api/documents/densitycrosses 200ms in production telemetry, whichever comes first.Out of scope
DocumentSearchCriteria(Markus round-1 #2: defer until a third aggregation endpoint lands)References