Skip to content

Refactor: Remove properties.root_id from mentions relationships #834

Description

@malibio

Summary

The mentions relationship currently stores properties.root_id on the relationship edge to speed up backlinks queries. This is denormalized/cached data that can become stale and adds complexity. We should compute roots dynamically using recursive graph traversal.

Current Behavior

When creating a mention:

  1. create_mention() computes the root of the source node via get_root_id() traversal
  2. Stores it as properties.root_id on the relationship
  3. get_mentioning_containers() reads properties.root_id to find backlink sources

Proposed Change

Phase 1: Implement dynamic root lookup

Refactor get_mentioning_containers() to compute roots dynamically:

  1. Get mentions where out = target_node
  2. For each mention's in (source), recursively traverse UP via has_child relationships to find the root
  3. Use the same recursive traversal pattern used for parent-child fetching (but going UP instead of DOWN)
  4. Return unique root nodes

Phase 2: Update frontend integration

Ensure the backlinks panel uses the refactored get_mentioning_containers():

  • Backlinks query runs in parallel with descendant loading (not awaiting each other)
  • Both update different parts of the UI independently

Phase 3: Remove properties.root_id from mention creation

  1. Remove root_id parameter from create_mention() in surreal_store.rs
  2. Remove root_id computation and storage in node_service.rs
  3. Simplify the mention relationship to just in (source) → out (target)

Phase 4: Migration cleanup (post-release consideration)

For existing installations, optionally clean up old data:

UPDATE relationship SET properties.root_id = NONE WHERE relationship_type = 'mentions';

Or leave it - the field becomes ignored dead data (no schema change needed since properties is flexible).

Benefits

  • Always accurate (reflects current hierarchy)
  • Simpler data model
  • No stale data if nodes move
  • Cleaner create_mention logic
  • Consistent pattern with other recursive traversals

Files to Modify

  • packages/core/src/db/surreal_store.rs - get_mentioning_containers(), create_mention()
  • packages/core/src/services/node_service.rs - create_mention()

Metadata

Metadata

Assignees

Labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions