fix: deduplicate concurrent sync state requests#969
Draft
Conversation
Two changes to eliminate redundant GET /api/sync/state?domain=... requests: 1. In-flight request deduplication for fetchRedisStateDomainSnapshot: When multiple callers (batch check, realtime handler, upload pre-merge) request the same domain concurrently, they now share a single HTTP request via a promise cache keyed by domain. The cache is cleared when the request settles (success or error). 2. Debounce requestCloudSyncCheck() across component mounts: Multiple components (Calendar, Stickies, Contacts) call requestCloudSyncCheck() on mount. These synchronous calls are now coalesced into a single listener notification using setTimeout(fn, 0). Co-authored-by: Ryo Lu <me@ryo.lu>
|
The preview deployment for ryos-dev is ready. 🟢 Open Preview | Open Build Logs | Open Application Logs Last updated at: 2026-03-15 09:18:35 CET |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Multiple duplicate
GET /api/sync/state?domain=...requests are fired concurrently for the same domain. From the server logs, the same domain (e.g.calendar,songs,contacts) was being fetched 3–5 times simultaneously:Root causes
No in-flight deduplication on
fetchRedisStateDomainSnapshot: When the batch check (checkRemoteUpdates), the realtime Pusher handler (handleRealtimeDomainUpdate), and upload pre-merge reads (uploadRedisStateDomain) all request the same domain concurrently, each fires a separate HTTP request.Rapid-fire
requestCloudSyncCheck()from component mounts: Multiple components (Calendar, Stickies, Contacts) callrequestCloudSyncCheck()synchronously on mount, each triggering the sync check listener.Fix
1. In-flight request deduplication for
fetchRedisStateDomainSnapshot(cloudSync.ts)Added a
Map<RedisSyncDomain, Promise>that caches in-flight requests. When multiple callers request the same domain concurrently, they share a single HTTP request. The cache is cleared when the request settles (success or error), so subsequent calls get fresh data.2. Debounce
requestCloudSyncCheck()(cloudSyncEvents.ts)Replaced the synchronous dispatch with a
setTimeout(fn, 0)coalescing pattern. AllrequestCloudSyncCheck()calls within the same event-loop tick are batched into a single listener notification.Testing
bun run build— compiles successfullybun run test:unit— all 89 tests pass