fix(service-worker): avoid storing redundant metadata for hashed assets (#42606)

The ServiceWorker needs to keep track of some metadata for unhashed
asset resources to know if/when they might need to be revalidated. This
applies to resources that do not exist on the filesystem at build-time
(and thus cannot be hashed), such as fonts or images loaded from
external sources. For hashed resources, this metadata is irrelevant,
because the hash is enough to verify that the content hasn't changed and
no revalidation is necessary.

Previously, the ServiceWorker would store such metadata for hashed
resources as well, even though it would never be used (thus taking up
space unnecessarily).

This commit fixes it by not storing metadata for hashed resources, i.e.
those that are included in an asset-group's `hashes` array.

PR Close #42606
This commit is contained in:
George Kalpakas 2021-07-08 16:22:49 +03:00 committed by atscott
parent a8698ce802
commit f592a12005
1 changed files with 0 additions and 2 deletions

View File

@ -454,7 +454,6 @@ export abstract class AssetGroup {
protected async maybeUpdate(updateFrom: UpdateSource, req: Request, cache: Cache):
Promise<boolean> {
const url = this.adapter.normalizeUrl(req.url);
const meta = await this.metadata;
// Check if this resource is hashed and already exists in the cache of a prior version.
if (this.hashes.has(url)) {
const hash = this.hashes.get(url)!;
@ -467,7 +466,6 @@ export abstract class AssetGroup {
if (res !== null) {
// Copy to this cache.
await cache.put(req, res);
await meta.write(req.url, {ts: this.adapter.time, used: false} as UrlMetadata);
// No need to do anything further with this resource, it's now cached properly.
return true;