refactor(service-worker): avoid unnecessary operations and remove unused code (#24127)
PR Close #24127
This commit is contained in:
parent
250527ca68
commit
45feb10c46
|
@ -225,7 +225,9 @@ export class Driver implements Debuggable, UpdateSource {
|
|||
// Initialization is the only event which is sent directly from the SW to itself,
|
||||
// and thus `event.source` is not a Client. Handle it here, before the check
|
||||
// for Client sources.
|
||||
if (data.action === 'INITIALIZE' && this.initialized === null) {
|
||||
if (data.action === 'INITIALIZE') {
|
||||
// Only initialize if not already initialized (or initializing).
|
||||
if (this.initialized === null) {
|
||||
// Initialize the SW.
|
||||
this.initialized = this.initialize();
|
||||
|
||||
|
@ -237,6 +239,9 @@ export class Driver implements Debuggable, UpdateSource {
|
|||
})());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Only messages from true clients are accepted past this point (this is essentially
|
||||
// a typecast).
|
||||
if (!this.adapter.isClient(event.source)) {
|
||||
|
@ -725,16 +730,6 @@ export class Driver implements Debuggable, UpdateSource {
|
|||
private async setupUpdate(manifest: Manifest, hash: string): Promise<void> {
|
||||
const newVersion = new AppVersion(this.scope, this.adapter, this.db, this.idle, manifest, hash);
|
||||
|
||||
// Try to determine a version that's safe to update from.
|
||||
let updateFrom: AppVersion|undefined = undefined;
|
||||
|
||||
// It's always safe to update from a version, even a broken one, as it will still
|
||||
// only have valid resources cached. If there is no latest version, though, this
|
||||
// update will have to install as a fresh version.
|
||||
if (this.latestHash !== null) {
|
||||
updateFrom = this.versions.get(this.latestHash);
|
||||
}
|
||||
|
||||
// Firstly, check if the manifest version is correct.
|
||||
if (manifest.configVersion !== SUPPORTED_CONFIG_VERSION) {
|
||||
await this.deleteAllCaches();
|
||||
|
|
Loading…
Reference in New Issue