Prevent duplicate reconciled message events with a keyed cache - #835
Prevent duplicate reconciled message events with a keyed cache#835qayshp wants to merge 2 commits into
Conversation
qayshp
left a comment
There was a problem hiding this comment.
Self-review complete. The cache-retention behavior is covered by the synthetic replay tests; I left one performance-oriented follow-up inline.
Validation updateValidated on SIP-enabled arm64 macOS 26.5.2 with Node 20.11.1 and npm 10.2.4.
The functional regression coverage passes, but the benchmark confirms that the linear cache can become material at unusually high volume. Validation against a representative busy server, or a decision to use a keyed cache, remains open before this draft is promoted. No messages were sent or received during validation. No screenshot is needed because this change has no visual surface. |
|
Superseding the earlier performance note: its linear-cache benchmark describes the prior implementation, not the current head. Message-event deduplication now uses a keyed |
Summary
Map-backed cache for high-volume message-event deduplicationRoot cause
The message poller periodically widens its query to seven days, but message event and state entries were pruned after one hour. A previously emitted row could therefore lose its GUID and state, then be classified as a new entry when the reconciliation lookback revisited it.
Simply extending the old array-backed event cache would also make high-volume message lookup increasingly expensive. The final implementation separates the two workloads:
KeyedEventCache, backed byMapfor keyed add/find/remove operationsEventCachearray and one-hour retentionImpact
Long-running servers no longer re-emit unchanged reconciled rows as
new-entryevents after the former one-hour deduplication window. Message lookup no longer performs a linear scan of the retained event set, while chat read-state deduplication keeps its existing storage and retention behavior.Validation
Passed on the current head:
node --test test/messageCacheRetention.test.cjs— 4/4 testsgit diff --checkThe tests cover full-lookback deduplication, expiry pruning, one-hour chat retention,
Map-backed message storage, unchanged array-backed chat storage, and duplicate-key behavior.tsc -p packages/server/tsconfig.json --noEmitstill reaches the existing unrelatedScheduledService.ts:39NodeJS.Timer/clearIntervaltype error.Fixes #765