Skip to content
This repository was archived by the owner on Apr 4, 2026. It is now read-only.

feat(casts): add root_parent tracking for thread identification#72

Merged
christopherwxyz merged 2 commits into
mainfrom
feature/root-parent-tracking
Jan 1, 2026
Merged

feat(casts): add root_parent tracking for thread identification#72
christopherwxyz merged 2 commits into
mainfrom
feature/root-parent-tracking

Conversation

@christopherwxyz

Copy link
Copy Markdown
Contributor

Summary

  • Add root_parent_hash, root_parent_fid, root_parent_url columns to casts table for O(1) thread identification
  • Resolve root parent during cast insertion via DB lookup or Hub traversal
  • Add backfill worker to populate existing casts
  • Leave root_parent NULL when chain is broken (never incorrectly assume non-root is root)

Changes

Migration (006_add_root_parent_columns.sql)

  • Adds 3 nullable columns: root_parent_fid, root_parent_hash, root_parent_url
  • Creates partial indexes for efficient lookups

Cast Processing (src/processor/database.rs)

  • resolve_root_parent(): Checks DB for parent's root, falls back to Hub traversal
  • resolve_root_from_hub(): Traverses parent chain via gRPC to find true root
  • Updated add_cast() to populate root_parent columns

Batch Operations (src/database/batch.rs)

  • Added parent_fid, root_parent_* fields to CastInsert
  • Updated bulk_insert_casts() for new columns

Backfill (src/backfill/root_parent.rs)

  • RootParentBackfill worker for existing casts
  • backfill_url_parents() for simple URL parent casts
  • Configurable batch size, max depth, delay

Semantics

Scenario root_parent_* value
Root cast (no parent) NULL
Reply with known root Points to root cast
Reply with URL parent root_parent_url set
Broken chain (parent missing) NULL

Test plan

  • Unit tests for extract_parent_from_proto()
  • Clippy passes with no warnings
  • All 199 tests pass
  • Manual test with real Hub connection
  • Run backfill on staging data

Add root_parent_hash, root_parent_fid, root_parent_url columns to enable
O(1) thread identification instead of O(n) recursive traversal.

- Add migration 006 with columns and indexes
- Update add_cast() to resolve root parent via DB lookup or Hub traversal
- Update CastInsert and bulk_insert_casts() for batch operations
- Leave root_parent NULL when chain is broken (never assume non-root is root)
- Add unit tests for extract_parent_from_proto()
Add backfill module to populate root_parent columns for existing casts:

- RootParentBackfill worker traverses parent chains via Hub
- Configurable batch size, max depth, and delay
- backfill_url_parents() for simple URL parent casts
- Leaves root_parent NULL when chain is broken (same behavior as insert)
@christopherwxyz
christopherwxyz merged commit 9f669b9 into main Jan 1, 2026
4 checks passed
@christopherwxyz
christopherwxyz deleted the feature/root-parent-tracking branch February 8, 2026 20:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant