Skip to content

Delete obsolete cache management code from SharedNodeStore #557

Closed

Description

@malibio

Overview

Delete the manual cache management from SharedNodeStore and ReactiveNodeService that has been replaced by ReactiveStructureTree (Issue #553, PR #566). Additionally, complete the removal of beforeSiblingId from the Node type and all usage in the codebase.

Background

  • ReactiveStructureTree now handles hierarchy queries via LIVE SELECT events with fractional ordering
  • SharedNodeStore's childrenCache and parentsCache are redundant
  • These caches cause synchronization issues and add unnecessary complexity
  • Per architecture review (docs/architecture/development/hierarchy-reactivity-architecture-review.md), cache management and beforeSiblingId should be completely removed
  • Issue Complete removal of beforeSiblingId - clean up fractional ordering migration #575 was merged but beforeSiblingId still exists on Node type and is actively used

Tasks

Phase 1: Remove beforeSiblingId from Node Type

CRITICAL: Zero beforeSiblingId references should remain in Node data model

  • Remove beforeSiblingId field from Node interface (packages/desktop-app/src/lib/types/node.ts:35)
  • Remove beforeSiblingId from NodeUpdate interface (packages/desktop-app/src/lib/types/node.ts:200)
  • Remove beforeSiblingId validation in isValidNode() (node.ts:258)
  • Remove all documentation comments referencing beforeSiblingId in node.ts

Phase 2: Update Services to Use Structure Store Instead

Replace all node.beforeSiblingId reads with structure store queries

Files to update:

  • reactive-node-service.svelte.ts (lines 154, 444, 836, 931, 1028, 1125, 1358)

    • Replace siblings.find(n => n.beforeSiblingId === targetId) with structure-based queries
    • Use structureTree.getChildren() to get ordered siblings
    • Calculate next sibling from ordered array instead of linked-list traversal
  • backend-adapter.ts (line 1072)

    • Remove beforeSiblingId from Node serialization
  • shared-node-store.ts (lines 725, 780)

    • Remove beforeSiblingId comparison in change detection
    • Remove beforeSiblingId dependency validation

Phase 3: SharedNodeStore Cache Cleanup

  • Delete cache Maps:

    • private childrenCache: Map<string | null, string[]>
    • private parentsCache: Map<string, string[]>
  • Delete cache methods:

    • updateChildrenCache()
    • addChildToCache()
    • removeChildFromCache()
    • clearChildrenCache()
  • Update getNodesForParent() to delegate to ReactiveStructureTree:

import { structureTree } from '$lib/stores/reactive-structure-tree.svelte';

getNodesForParent(parentId: string | null): Node[] {
  const childIds = structureTree.getChildren(parentId ?? '__root__');
  return childIds.map(id => this.nodes.get(id)).filter((n): n is Node => n !== undefined);
}
  • Update getParentsForNode() to delegate to ReactiveStructureTree:
getParentsForNode(nodeId: string): Node[] {
  const parentIds = structureTree.getParentsForNode(nodeId);
  return parentIds.map(id => this.nodes.get(id)).filter((n): n is Node => n !== undefined);
}

Phase 4: ReactiveNodeService Cleanup

  • Delete _sortedChildrenCache
  • Delete invalidateSortedChildrenCache()
  • Remove all calls to cache invalidation methods
  • Update sortChildrenByBeforeSiblingId() to use structure store ordering instead

Phase 5: Test Updates

  • Update tests that read node.beforeSiblingId
  • Update tests that call removed cache methods
  • Verify all hierarchy queries work via ReactiveStructureTree
  • Update test utilities that create nodes with beforeSiblingId

Key Implementation Pattern

Finding next sibling (OLD - using beforeSiblingId):

const nextSibling = siblings.find(n => n.beforeSiblingId === currentNodeId);

Finding next sibling (NEW - using structure store):

const orderedSiblings = structureTree.getChildren(parentId ?? '__root__');
const currentIndex = orderedSiblings.indexOf(currentNodeId);
const nextSibling = currentIndex >= 0 && currentIndex < orderedSiblings.length - 1
  ? this.findNode(orderedSiblings[currentIndex + 1])
  : null;

Acceptance Criteria

  • ZERO references to node.beforeSiblingId remain in source code
  • beforeSiblingId field removed from Node and NodeUpdate interfaces
  • All cache-related code removed from SharedNodeStore
  • getNodesForParent() and getParentsForNode() delegate to ReactiveStructureTree
  • All sibling queries use structure store instead of linked-list traversal
  • No calls to cache methods remain in codebase
  • All tests pass
  • No compilation errors

Dependencies

Related Issues

Activity

  1. self-assigned this
    on Nov 21, 2025
  2. changed the title [-]Delete obsolete manual cache management code[/-] [+]Delete obsolete cache management code from SharedNodeStore[/+] on Nov 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions