Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(service-worker): prevent duplicate fetches during concurrent update checks #61443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

arturovt
Copy link
Contributor

Previously, multiple simultaneous calls to checkForUpdate() could result in redundant fetches and hashing of the update manifest, leading to unnecessary network and CPU usage.

This change introduces a mechanism to track an in-progress update check using a cached promise (ongoingCheckForUpdate). Subsequent calls to checkForUpdate() while a check is in progress will return the same promise instead of triggering a new request.

Once the check completes (successfully or not), the cached promise is cleared, allowing future update checks to proceed normally.

This improves efficiency and prevents overlapping update logic in applications that may invoke checkForUpdate() from multiple sources (e.g. polling, manual triggers).

@pullapprove pullapprove bot requested a review from atscott May 16, 2025 22:26
@angular-robot angular-robot bot added the area: service-worker Issues related to the @angular/service-worker package label May 16, 2025
@ngbot ngbot bot added this to the Backlog milestone May 16, 2025
@arturovt arturovt force-pushed the fix/service-worker-concurrent-checkForUpdate branch from 2bcbcd5 to 62d7870 Compare May 22, 2025 16:59
…te checks

Previously, multiple simultaneous calls to `checkForUpdate()` could result in redundant
fetches and hashing of the update manifest, leading to unnecessary network and CPU usage.

This change introduces a mechanism to track an in-progress update check using a cached
promise (`ongoingCheckForUpdate`). Subsequent calls to `checkForUpdate()` while a check
is in progress will return the same promise instead of triggering a new request.

Once the check completes (successfully or not), the cached promise is cleared,
allowing future update checks to proceed normally.

This improves efficiency and prevents overlapping update logic in applications that
may invoke `checkForUpdate()` from multiple sources (e.g. polling, manual triggers).
@arturovt arturovt force-pushed the fix/service-worker-concurrent-checkForUpdate branch from 62d7870 to 88916e1 Compare June 3, 2025 17:34
@atscott atscott added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels Jun 3, 2025
@kirjs
Copy link
Contributor

kirjs commented Jun 3, 2025

This PR was merged into the repository by commit 6adf022.

The changes were merged into the following branches: main, 20.0.x

kirjs pushed a commit that referenced this pull request Jun 3, 2025
…te checks (#61443)

Previously, multiple simultaneous calls to `checkForUpdate()` could result in redundant
fetches and hashing of the update manifest, leading to unnecessary network and CPU usage.

This change introduces a mechanism to track an in-progress update check using a cached
promise (`ongoingCheckForUpdate`). Subsequent calls to `checkForUpdate()` while a check
is in progress will return the same promise instead of triggering a new request.

Once the check completes (successfully or not), the cached promise is cleared,
allowing future update checks to proceed normally.

This improves efficiency and prevents overlapping update logic in applications that
may invoke `checkForUpdate()` from multiple sources (e.g. polling, manual triggers).

PR Close #61443
@kirjs kirjs closed this in 6adf022 Jun 3, 2025
@arturovt arturovt deleted the fix/service-worker-concurrent-checkForUpdate branch June 3, 2025 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action: merge The PR is ready for merge by the caretaker area: service-worker Issues related to the @angular/service-worker package target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants