Skip to content

Commit

Permalink
perf: optimize cache lookup during external resources synchronization
Browse files Browse the repository at this point in the history
  • Loading branch information
QRuhier committed Oct 11, 2024
1 parent 6b441fc commit 0ace5cb
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions drama-queen/src/core/tools/externalResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,22 @@ async function filterTransformedManifest(
// Open the specified cache
const cacheForManifest = await caches.open(cacheName)

// If the cache is available, filter the transformedManifest for keeping only files that are not cached yet
if (cacheForManifest) {
return await asyncFilter(transformedManifest, async (resourceUrl) => {
const cacheResponse = await cacheForManifest.match(resourceUrl)
return !cacheResponse?.ok
})
// If cache is not available, return a copy of transformedManifest
if (!cacheForManifest) {
return [...transformedManifest]
}

// If cache is not available, return a copy of transformedManifest
return [...transformedManifest]
// Get all urls from the cache
const cachedUrls = (await cacheForManifest.keys()).map(
(request) => request.url
)

// filter the transformedManifest for keeping only files that are not cached yet
const uncachedResources = transformedManifest.filter(
(resourceUrl) => !cachedUrls.includes(resourceUrl)
)

return uncachedResources
}

// Cache every external resources (not already cached) for a particular questionnaire
Expand Down

0 comments on commit 0ace5cb

Please sign in to comment.