Automattic / Automattic/cortext

Denormalize trait membership (terms/traits sidecar)

Open
#301 0 comments 0 reactions 0 assignees View on GitHub
area: performance type: enhancement
Dominant language
JavaScript
Stars
51
Forks
2
Avg merge
3h 12m
Merged PRs (30d)
8

Description

Membership runs through the `crtxt_collection` taxonomy, so every document query adds a `tax_query` JOIN over `term_relationships` and `term_taxonomy`, and resolving a document's trait hits the term tables. We accepted that in #280: the JOIN was ~1-3 ms, well inside the noise, and the boot win mattered more. But it scales with the workspace, so at some point it's worth taking off the hot paths.

**Proposed solution:** keep a denormalized copy of document→trait membership, like the field-value index, so the hot paths skip the JOIN. Prime the term lookups (`term_id_for_trait`, `all_trait_ids`, `find_trait_for_document`) once per request too.

Contributor guide

Open the contributing guide

Research direction

Start by tracing the crtxt_collection taxonomy and the existing field-value index through the document-query hot paths. Compare term_id_for_trait, all_trait_ids, and find_trait_for_document, then define completion as denormalized document-to-trait membership that avoids the JOIN while preserving behavior and primes those lookups once per request.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
databases, performance
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.