Problem
When an entry_state_changed SSE event arrives, the handler in src/lib/cache/event-handlers.ts:117-129 looks up the subscription from the global subscriptions collection to compute tag count deltas:
const subscription = collections.subscriptions.get(subscriptionId);
if (subscription) {
// compute tag deltas
}
Per Goal 4 ("Everything works even if we don't have per-subscription data"), the subscription may not be in the collection because subscriptions are only loaded when a tag section is expanded in the sidebar. If the user hasn't expanded the relevant tag section, the subscription won't be in the collection, and tag/uncategorized unread count adjustments will be silently skipped.
The adjustSubscriptionUnreadInCollection call (line 120) also silently skips if the subscription doesn't exist.
Impact
- Tag unread counts in the sidebar drift from reality
- Uncategorized unread counts drift
- Subscription-level unread counts are not tracked for subscriptions that haven't been loaded
This violates Goal 4.
Possible fixes
- When subscription lookup fails, skip the per-subscription/tag delta calculation (which we already do) but leave the global "all" count update intact (which already works). This is acceptable as an approximation since the tag/subscription counts will be corrected when the user expands the tag section.
- Alternatively, fetch subscription data from the server when needed (adds latency/complexity).
- Accept the approximation but add a comment explaining why and ensure tag counts are refreshed when tags are expanded.
Option 1 is already what happens, but we should at minimum ensure the global count adjustments are correct regardless. The current code IS correct for the global "all" count (line 114 runs unconditionally). The issue is only with tag/subscription/uncategorized counts.
Actually, on re-reading the code, this is working as designed - the global counts are always updated, and the per-subscription/tag counts are updated when subscription data is available. This is probably acceptable given Goal 4. The main concern is that tag counts could drift. We should document this tradeoff and ensure tag counts are refreshed when expanded.
Related to #580 (tanstack-db branch).
-- Claude
Problem
When an
entry_state_changedSSE event arrives, the handler insrc/lib/cache/event-handlers.ts:117-129looks up the subscription from the global subscriptions collection to compute tag count deltas:Per Goal 4 ("Everything works even if we don't have per-subscription data"), the subscription may not be in the collection because subscriptions are only loaded when a tag section is expanded in the sidebar. If the user hasn't expanded the relevant tag section, the subscription won't be in the collection, and tag/uncategorized unread count adjustments will be silently skipped.
The
adjustSubscriptionUnreadInCollectioncall (line 120) also silently skips if the subscription doesn't exist.Impact
This violates Goal 4.
Possible fixes
Option 1 is already what happens, but we should at minimum ensure the global count adjustments are correct regardless. The current code IS correct for the global "all" count (line 114 runs unconditionally). The issue is only with tag/subscription/uncategorized counts.
Actually, on re-reading the code, this is working as designed - the global counts are always updated, and the per-subscription/tag counts are updated when subscription data is available. This is probably acceptable given Goal 4. The main concern is that tag counts could drift. We should document this tradeoff and ensure tag counts are refreshed when expanded.
Related to #580 (tanstack-db branch).
-- Claude