fix(service-worker): use correct names when listing `CacheDatabase` tables (#42622)

`CacheDatabase` uses the un-prefixed table names to interact with
database tables. However, the `list()` method returns the raw, prefixed
table names (which are not useful, since they cannot be used to
open/delete a table).

This commit fixes this by removing the prefix from the cache names
returned by the `list()` method.

NOTE:
This method is currently not used anywhere, so this change does not
affect the ServiceWorker behavior.

PR Close #42622
This commit is contained in:
George Kalpakas 2021-06-23 15:27:50 +03:00 committed by Jessica Janiuk
parent 53fe557da7
commit 7507ed2e54
1 changed files with 4 additions and 1 deletions

View File

@ -31,7 +31,10 @@ export class CacheDatabase implements Database {
const prefix = `${this.cacheNamePrefix}:`;
const allCacheNames = await this.scope.caches.keys();
const dbCacheNames = allCacheNames.filter(name => name.startsWith(prefix));
return dbCacheNames;
// Return the un-prefixed table names, so they can be used with other `CacheDatabase` methods
// (for example, for opening/deleting a table).
return dbCacheNames.map(name => name.slice(prefix.length));
}
async open(name: string, cacheQueryOptions?: CacheQueryOptions): Promise<Table> {