Skip to content

Deduplicate concurrent in-flight select() requests in TTLSelectCachingDAO#4928

Merged
kgrgreer merged 1 commit intokgrgreer:developmentfrom
abdelaziz-mahdy:add-inflight-dedup-ttl-select-cache
Mar 23, 2026
Merged

Deduplicate concurrent in-flight select() requests in TTLSelectCachingDAO#4928
kgrgreer merged 1 commit intokgrgreer:developmentfrom
abdelaziz-mahdy:add-inflight-dedup-ttl-select-cache

Conversation

@abdelaziz-mahdy
Copy link
Collaborator

Problem

TTLSelectCachingDAO only caches resolved results. When multiple concurrent callers issue identical select() queries before the first one resolves, each caller fires a separate server request. In batch scenarios (e.g., 300 identical queries triggered simultaneously), this produces 300 redundant network round-trips.

Solution

Store the in-flight promise in the cache immediately on miss. Concurrent callers with the same cache key receive the shared promise instead of starting new requests. When the promise resolves, replace it with the cloned result for subsequent cache hits. On error, remove the failed entry so the next caller retries.

Changes

  • Store the delegate's promise in this.cache[key] before it resolves, so concurrent select_() calls with the same key share one request
  • Clone the result when returning from an in-flight promise hit, preserving the existing cache corruption protection
  • Remove failed entries on error instead of clearing the entire cache

@abdelaziz-mahdy abdelaziz-mahdy force-pushed the add-inflight-dedup-ttl-select-cache branch from d9394b3 to 22333ad Compare March 23, 2026 13:59
@kgrgreer kgrgreer merged commit eea64a5 into kgrgreer:development Mar 23, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants