workers-sdk icon indicating copy to clipboard operation
workers-sdk copied to clipboard

fix(pages-shared): Store asset key instead of body in preservation cache

Open jahands opened this issue 1 year ago • 4 comments

Fixes # PAGES-2169

What this PR solves / how to test:

Stores assetKey in preservation cache rather than the actual asset so that we don't write rarely used bytes to cache. Also now only writes to cache once rather than on every request.

Tested in RC and ensured preservation cache still serves correctly

Author has addressed the following:

  • Tests
    • [x] Included
    • [ ] Not necessary because:
  • Changeset (Changeset guidelines)
    • [x] Included
    • [ ] Not necessary because:
  • Associated docs
    • [ ] Issue(s)/PR(s):
    • [ ] Not necessary because:

jahands avatar Jan 20 '24 00:01 jahands

🦋 Changeset detected

Latest commit: eb276d0e0f685c372de04abcaaabe057f076ae93

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cloudflare/pages-shared Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar Jan 20 '24 00:01 changeset-bot[bot]

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8898342043/npm-package-wrangler-4797

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/4797/npm-package-wrangler-4797

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8898342043/npm-package-wrangler-4797 dev path/to/script.js
Additional artifacts:
npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8898342043/npm-package-create-cloudflare-4797 --no-auto-update
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8898342043/npm-package-cloudflare-kv-asset-handler-4797
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8898342043/npm-package-miniflare-4797
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8898342043/npm-package-cloudflare-pages-shared-4797
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8898342043/npm-package-cloudflare-vitest-pool-workers-4797

Note that these links will no longer work once the GitHub Actions artifact expires.


[email protected] includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 3.20240419.0
workerd 1.20240419.0 1.20240419.0
workerd --version 1.20240419.0 2024-04-19

Please ensure constraints are pinned, and miniflare/workerd minor versions match.

github-actions[bot] avatar Jan 20 '24 00:01 github-actions[bot]

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 70.71%. Comparing base (2789f26) to head (c77fdc0). Report is 74 commits behind head on main.

:exclamation: Current head c77fdc0 differs from pull request most recent head eb276d0. Consider uploading reports for the commit eb276d0 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4797      +/-   ##
==========================================
- Coverage   72.44%   70.71%   -1.74%     
==========================================
  Files         331      291      -40     
  Lines       17298    15164    -2134     
  Branches     4422     3859     -563     
==========================================
- Hits        12532    10723    -1809     
+ Misses       4766     4441     -325     

see 160 files with indirect coverage changes

codecov[bot] avatar Jan 20 '24 00:01 codecov[bot]

@jahands - would you like to update with the suggestions given by @mrbbot before we merge this?

petebacondarwin avatar Feb 02 '24 12:02 petebacondarwin

@jahands - do you have time to follow up on this PR?

petebacondarwin avatar Mar 11 '24 20:03 petebacondarwin

@petebacondarwin We had internal issues blocking this and #4814 but we're finally back to working on these this week.

jahands avatar Apr 22 '24 21:04 jahands

Great! Let me know when you are ready.

petebacondarwin avatar Apr 22 '24 21:04 petebacondarwin

@petebacondarwin This should be good to go! I didn't do a great job rebasing and ended up force-pushing one big commit, but I called out the main fixup's that I did in addition to the feedback

jahands avatar Apr 22 '24 23:04 jahands

Tested that the preservationCacheV1 (fallback) test passes without any of these changes, indicating that the V1 logic is preserved correctly

jahands avatar Apr 22 '24 23:04 jahands

After thinking about it more, I realized that we want to periodically reset the Preservation cache expiration: https://github.com/cloudflare/workers-sdk/pull/4797/commits/3fad62d5874d7d1282153b7727079521cda063e4 Otherwise, it'll expire every week, which could cause issues in SPAs if someone deletes an asset right before the week is up.

jahands avatar Apr 23 '24 03:04 jahands

Now I think this is done for reallll :)

jahands avatar Apr 23 '24 03:04 jahands

Rebased for #5694 to fix the CI failure

jahands avatar Apr 24 '24 18:04 jahands

(another rebase)

jahands avatar Apr 24 '24 18:04 jahands