feat(themen): count documents across the whole sub-topic tree (#698) #701
Reference in New Issue
Block a user
Delete Branch "worktree-feat+issue-698-themen-subtree-count"
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?
Closes #698.
Each
/themenbox now counts documents across its whole sub-topic tree (distinct), so the number matches what/documents?tag=Xactually returns. Implements Option B: a newsubtreeDocumentCountfield — reader surfaces read the rollup, admin surfaces keep the directdocumentCount.What changed
Backend
TagTreeNodeDTOgainssubtreeDocumentCount;getTagTree()maps both counts onto each node from two aggregate queries (no N+1 — NFR-PERF-THEMEN-01).TagRepository.findSubtreeDocumentCountsPerTag(): one recursive-CTE tag closure (depth guard ≤50) joined todocument_tags,GROUP BY ancestor_idwithCOUNT(DISTINCT document_id)(REQ-THEMEN-01/02/03/06). DirectdocumentCountis unchanged.getTagTree()JavaDoc +tag/README.md.Frontend
hasAnyDocumentskeys onsubtreeDocumentCount > 0(single field read)./themenpage (header, child rows, aria-labels) and the dashboardThemenWidgetdisplaysubtreeDocumentCount. A parent with 0 direct docs but populated children now shows a non-zero total.documentCount).Tests
postgres:16-alpine, Testcontainers) integration tests: leaf = direct (AC#4), shared doc counted once (AC#1+#2), full grandchild depth (AC#3), empty subtree absent (REQ-THEMEN-05), cycle terminates via the guard (REQ-THEMEN-06), and rollup == distinct documents from the real search expansion (AC#7 parity).hasAnyDocumentstests; AC#5 component test; admin characterization tests pinning previews to the direct count (AC#8).Notes for the reviewer
generated/api.tswas hand-edited to matchgenerate:apioutput (codegen needs a live dev backend); re-running it should be byte-equivalent.🤖 Generated with Claude Code
fc2c726961toa76999c3d4