pln-planning-tools / Starmap

Roadmap Planning Tool
https://starmap.site
Other
20 stars 8 forks source link

fix(sw): return 200-299,304 responses immediately #383

Closed SgtPooki closed 11 months ago

SgtPooki commented 11 months ago

fixes #380

This PR updates the caching strategy to prevent the duplicate call to the backend if we have a cached call, and returns it immediately.

One thing to note, is that vercel-cached responses return HTTP 304 responses, and response.ok didn't check for that. This PR also addresses this.

So, a call to the backend vercel function, that calls github does NOT happen IFF:

  1. There is a cached response
  2. That cached response has a status code of 200-299
  3. That cached response has a status code of 304;

A backend call to the backend vercel function, that calls github, WILL happen IFF:

  1. There is no cached response
  2. The cached response is a failed request (github error, vercel error, etc)
  3. The cached response was a modified result.
  4. The cached response's max-age is "too old"
vercel[bot] commented 11 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
starmaps ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 23, 2023 5:50am
SgtPooki commented 11 months ago

Verified that subsequent load is almost instant:

  1. Load page with no cache (application data cleared)
  2. data pulls fully from vercel backend cache (cached from previous attempts, so faster than fully from github, but still takes longer than when it's cached in the sw for HUGE roadmaps)
  3. reload page
  4. page loads almost instantaneously

Verified that cache is invalidated for updated github items (description updates):

  1. load page
  2. edit github issue
  3. reload page (not clearing cache.. ) === github issue is not updated in starmap, but a popup appears showing new data exists
  4. reload page === github issue that was stale is updated in starmap, but the rest loads very quickly
  5. reload page === latest github issue data (which is cached in SW) loads instantly for everything

@whizzzkid @momack2 please review. Preview urls for the urls Molly gave in slack are: