Skip to content
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

Update the workbox-expiration IDB data model #1883

Merged
merged 7 commits into from
Feb 6, 2019
Merged

Conversation

philipwalton
Copy link
Member

R: @jeffposnick

Fixes #1398, Fixes #1400.

This PR updates the IDB data model used by workbox-expiration, switching it to from multiple databases (named the same as the cache name), to a single database (named workbox-expiration) where the entries in the database have a cacheName property.

I've also updated how expiration happens to make it more efficient. Previously the entire contents of the object store would be read out, the purgeable entires were determined, and then in a second transaction those entries would be removed. In this PR I've moved the logic that determines what needs to be expired into CacheTimestampsModel, so it can all happen inside a single transaction.

Lastly, I had to update our IDB mocks yet again due to bugs I found when running tests. I've manually confirmed that the logic in this PR does work in Chrome, FF, and Safari's IDB implementations.

// but don't `await` it as we don't want to block the response.
const updateTimestampDone = cacheExpiration.updateTimestamp(request.url);
if (event) {
event.waitUntil(updateTimestampDone);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're going to need to put this in a try/catch, à la https://github.com/GoogleChrome/workbox/pull/1457/files

Samsung Internet 6.4, which I believe we're still trying to support, breaks when you call event.waitUntil() asynchronously: #1435 (comment)

@@ -155,7 +163,7 @@ class Plugin {
return true;
}

// If we have a valid headerTime, then our response is fresh iff the
// If we have a valid headerTime, then our response is fresh if the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh. I just saw the red underline in my editor and changed it without thinking.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Updated.

Copy link
Member Author

@philipwalton philipwalton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Jeff, I updated the PR with these changes.

@@ -155,7 +163,7 @@ class Plugin {
return true;
}

// If we have a valid headerTime, then our response is fresh iff the
// If we have a valid headerTime, then our response is fresh if the
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh. I just saw the red underline in my editor and changed it without thinking.

@@ -155,7 +163,7 @@ class Plugin {
return true;
}

// If we have a valid headerTime, then our response is fresh iff the
// If we have a valid headerTime, then our response is fresh if the
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Updated.

@workbox-pr-bot
Copy link
Collaborator

PR-Bot Size Plugin

Changed File Sizes

File Before After Change GZipped
packages/workbox-background-sync/build/workbox-background-sync.prod.js 3.51 KB 3.61 KB +3% 1.56 KB
packages/workbox-build/build/index.js 4.02 KB 3.64 KB -9% 1.36 KB
packages/workbox-cli/build/app.js 6.76 KB 5.58 KB -17% 1.98 KB 🎉
packages/workbox-cli/build/bin.js 2.32 KB 1.16 KB -50% 580 B 🎉
packages/workbox-core/build/workbox-core.prod.js 7.47 KB 5.43 KB -27% 2.36 KB 🎉
packages/workbox-precaching/build/workbox-precaching.prod.js 5.80 KB 4.21 KB -27% 1.68 KB 🎉
packages/workbox-range-requests/build/workbox-range-requests.prod.js 1.63 KB 1.52 KB -7% 763 B
packages/workbox-routing/build/workbox-routing.prod.js 2.87 KB 3.23 KB +13% 1.42 KB ☠️
packages/workbox-strategies/build/workbox-strategies.prod.js 5.09 KB 4.87 KB -4% 1.19 KB
packages/workbox-streams/build/workbox-streams.prod.js 1.57 KB 1.38 KB -12% 684 B 🎉
packages/workbox-sw/build/workbox-sw.js 1.50 KB 1.34 KB -11% 747 B 🎉
packages/workbox-webpack-plugin/build/generate-sw.js 8.04 KB 5.29 KB -34% 1.84 KB 🎉
packages/workbox-webpack-plugin/build/index.js 742 B 349 B -53% 255 B 🎉
packages/workbox-webpack-plugin/build/inject-manifest.js 10.30 KB 7.22 KB -30% 2.48 KB 🎉

New Files

File Size GZipped
packages/workbox-broadcast-update/build/workbox-broadcast-update.prod.js 1.86 KB 936 B
packages/workbox-expiration/build/workbox-expiration.prod.js 2.84 KB 1.24 KB
packages/workbox-google-analytics/build/workbox-offline-ga.prod.js 1.89 KB 891 B

All File Sizes

View Table
File Before After Change GZipped
packages/workbox-background-sync/build/workbox-background-sync.prod.js 3.51 KB 3.61 KB +3% 1.56 KB
packages/workbox-broadcast-update/build/workbox-broadcast-update.prod.js 1.86 KB 936 B
packages/workbox-build/build/_types.js 41 B 41 B 0% 61 B
packages/workbox-build/build/index.js 4.02 KB 3.64 KB -9% 1.36 KB
packages/workbox-cacheable-response/build/workbox-cacheable-response.prod.js 587 B 587 B 0% 350 B
packages/workbox-cli/build/app.js 6.76 KB 5.58 KB -17% 1.98 KB 🎉
packages/workbox-cli/build/bin.js 2.32 KB 1.16 KB -50% 580 B 🎉
packages/workbox-core/build/workbox-core.prod.js 7.47 KB 5.43 KB -27% 2.36 KB 🎉
packages/workbox-expiration/build/workbox-expiration.prod.js 2.84 KB 1.24 KB
packages/workbox-google-analytics/build/workbox-offline-ga.prod.js 1.89 KB 891 B
packages/workbox-navigation-preload/build/workbox-navigation-preload.prod.js 660 B 660 B 0% 323 B
packages/workbox-precaching/build/workbox-precaching.prod.js 5.80 KB 4.21 KB -27% 1.68 KB 🎉
packages/workbox-range-requests/build/workbox-range-requests.prod.js 1.63 KB 1.52 KB -7% 763 B
packages/workbox-routing/build/workbox-routing.prod.js 2.87 KB 3.23 KB +13% 1.42 KB ☠️
packages/workbox-strategies/build/workbox-strategies.prod.js 5.09 KB 4.87 KB -4% 1.19 KB
packages/workbox-streams/build/workbox-streams.prod.js 1.57 KB 1.38 KB -12% 684 B 🎉
packages/workbox-sw/build/workbox-sw.js 1.50 KB 1.34 KB -11% 747 B 🎉
packages/workbox-webpack-plugin/build/generate-sw.js 8.04 KB 5.29 KB -34% 1.84 KB 🎉
packages/workbox-webpack-plugin/build/index.js 742 B 349 B -53% 255 B 🎉
packages/workbox-webpack-plugin/build/inject-manifest.js 10.30 KB 7.22 KB -30% 2.48 KB 🎉

Workbox Aggregate Size Plugin

8.78KB gzip'ed (59% of limit)
21.99KB uncompressed

@philipwalton philipwalton merged commit 4e481a9 into next Feb 6, 2019
@philipwalton philipwalton deleted the expiration-idb branch February 6, 2019 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants