Repository navigation
Description
Context
Current implementation in HttpAdapter and TauriAdapter performs a GET request before every DELETE operation to capture node metadata for event emission. This was identified during code review of PR #222.
Current Pattern:
async deleteNode(id: string): Promise<void> {
// Fetch node before deletion to get metadata for events
const nodeBeforeDeletion = await this.getNode(id);
const response = await fetch(..., { method: 'DELETE' });
// Emit events with metadata from fetched node
if (nodeBeforeDeletion) {
eventBus.emit<NodeDeletedEvent>({ ... });
}
}Problem
Performance Impact:
- 2x HTTP overhead per delete operation (GET + DELETE instead of just DELETE)
- For batch deletions (e.g., cleaning up 100 nodes), this doubles HTTP requests from 100 to 200
- Extra latency for every delete operation
Root Cause:
- Backend returns minimal response on DELETE (no node metadata)
- Events require
parentIdand other metadata - Frontend must fetch before delete to capture this data
Proposed Solutions
Option A: Backend Returns Deleted Node Metadata (Recommended)
Modify backend DELETE endpoint to return the deleted node data in response:
// Current: Returns 204 No Content
DELETE /api/nodes/{id} -> 204
// Proposed: Returns deleted node data
DELETE /api/nodes/{id} -> 200 { id, parentId, nodeType, ... }Pros:
- ✅ Eliminates extra GET request
- ✅ Proper REST pattern (DELETE can return entity representation)
- ✅ Single source of truth (backend knows what was deleted)
Cons:
- ❌ Requires backend changes (Issue Backend: Implement idempotent DELETE for REST compliance #219 should be addressed first)
Option B: Cache Node Metadata in Frontend State
Maintain node metadata cache in frontend (ReactiveNodeService):
private nodeMetadataCache = new Map<string, { parentId: string | null, nodeType: string }>();
async deleteNode(id: string): Promise<void> {
const metadata = this.nodeMetadataCache.get(id);
// ... delete operation
// Use cached metadata for events
}Pros:
- ✅ No backend changes needed
- ✅ Eliminates extra fetch
Cons:
- ❌ Cache can become stale
- ❌ Memory overhead for large node counts
- ❌ Complex cache invalidation logic
Option C: Conditional Fetch Based on Subscriber Count
Only fetch metadata if event subscribers exist:
async deleteNode(id: string): Promise<void> {
const needsMetadata = eventBus.hasActiveSubscribers('node:deleted') ||
eventBus.hasActiveSubscribers('hierarchy:changed');
const nodeBeforeDeletion = needsMetadata ? await this.getNode(id) : null;
// ... rest of delete logic
}Pros:
- ✅ Optimizes for no-subscriber case
- ✅ Simple to implement
Cons:
- ❌ Still 2x overhead when subscribers exist (common case)
- ❌ Requires EventBus API change
Recommendation
Phase 1 (Current): Accept 2x overhead as documented trade-off
Phase 2: Implement Option A when addressing Issue #219 (backend DELETE improvements)
Phase 3: Add performance metrics to track actual impact
Acceptance Criteria
- Backend DELETE returns deleted node metadata
- Frontend adapters use response metadata for events
- Eliminate extra GET request before DELETE
- All event emission tests still pass
- Performance benchmarks show improvement
- No regression in event emission behavior
Related Issues
- Backend: Implement idempotent DELETE for REST compliance #219 - Backend DELETE idempotence (prerequisite)
- Session 4: Complete Phase 2 Event System Tests (Issue #211 - Section 8) #222 - Event emission implementation (PR)
- Implement comprehensive test coverage for critical node operations (99.9% complete - 1 test remaining) #208 - Comprehensive test coverage (parent epic)
Metrics to Track
- Before: 2 HTTP requests per delete (GET + DELETE)
- After: 1 HTTP request per delete (DELETE with metadata response)
- Improvement: 50% reduction in delete operation overhead
Priority: Medium
Complexity: Medium (requires backend + frontend changes)
Estimated Impact: High (affects every delete operation)
Activity
malibio commentedon Dec 5, 2025
Architecture has changed significantly since this was written:
If performance issues are found, create new issues against current architecture.