Skip to content

Create static TopicIndex cache #116

Closed
Closed

Description

@JeremyCaney

Whenever referenceTopic is passed to most ITopicRepository.Load() implementation, it ultimately needs to be indexed via referenceTopic.GetRootTopic().GetTopicIndex(). This requires crawling the entire tree each request. Meanwhile, consumers like the CachedTopicService end up maintaining their own cache. Instead, provide a static reference to a list of TopicIndex instances keyed by their root topic instance.

While this isn't strictly necessary for lazy-loading (#111), it provides an important performance foundation for lazy-loading capabilities, such as dynamically resolving associations and merging ascendants into an existing tree.

Garbage Handling

This will need to use a ConditionalWeakTable<> (CWT) to make sure that this doesn't hold onto e.g., one-time indexes no longer referenced by other code. Otherwise, this could result in a memory leak with every one-off load potentially being held onto indefinitely.

Tasks

  • TopicIndexRegistry: Concurrency-safe storage, with hooks for attaching, detaching, and assigning IDs, assigned on Parent
  • Consolidate CachedTopicRepository onto the live index, retiring its redundant _topicIdIndex

Activity

  1. added this to the OnTopic 6.0.0 milestone on Jul 25, 2026
  2. added theissue type on Jul 25, 2026
  3. self-assigned this
    on Jul 25, 2026
  4. added a commit that references this issue on Aug 7, 2026
  5. added
    Status 5: CompleteTask is considered complete, and ready for deployment.
    and removed on Aug 9, 2026
  6. JeremyCaney commented on Aug 9, 2026

    @JeremyCaney
    MemberAuthor

    Merged with cb8e2ca:

    • TopicIndexRegistry: Concurrency-safe storage, with hooks for attaching, detaching, and assigning IDs, assigned on Parent
      • Introduced the TopicIndexRegistry as a CWT-backed cache, plus its add, remove, and save event handlers (a15ae85) with unit tests (0587bbc)
      • Converted TopicIndex to ConcurrentDictionary<> (ffb77d9)
      • Wired-up TopicIndexRegistry "event" handlers; hooks it into Topic add, remove, and save events, including Parent assignment (273beeb)
      • Introduced GetLiveTopicIndex() method to Topic (a18d8d5)
      • Use GetLiveTopicIndex() over GetTopicIndex() (4757d89)
      • Skip orphaned topics in AddTopic() (9ef4189) with unit tests (e37be61)
      • Ensured proper sort order for GetTopicUpdates, so parents are always indexed before children (0a30ecd) with unit tests (21e5277)
    • Consolidate CachedTopicRepository onto the live index, retiring its redundant _topicIdIndex
      • Removed _topicIdIndex from cached repository (ae279e9)
      • Added unit tests for ID index in cached test (b7284fe)
    • Cleanup: Fixed minor spelling errors in comments (94b763c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Area: RepositoriesRelates to the `ITopicRepository` interface or one of its implementations.Priority: 1Severity 2: MajorStatus 5: CompleteTask is considered complete, and ready for deployment.Type: ImprovementImproves the functionality or interface of an existing feature.

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions