Add sources cache to Nuxt app #5288
Merged
+92
−59
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes
Fixes #5287 by @obulat
Description
This PR uses the server route with
defineCachedFunction
to cache the/stats
response for an hour. This is following SWR (stale-while-revalidate) principle, so if a request to update the stats fails, the cached (even outdated) version is still returned.This PR also simplifies the provider store to combine the fetch state for images and audio into a single object since we don't really need the distinction between the media types.
The requests don't add the auth token to the API request, but it should be okay because the request is only sent once an hour.
Testing Instructions
Run the app locally, and open the
localhost:8443/sources
page. You should see the log about/stats
requests (for audio and images) in the terminal (not the browser console). Now, reload the page several times. There should be no other requests logged, since the data is cached in the nitro server.Checklist
Update index.md
).main
) or a parent feature branch.ov just catalog/generate-docs
for catalogPRs) or the media properties generator (
ov just catalog/generate-docs media-props
for the catalog or
ov just api/generate-docs
for the API) where applicable.Developer Certificate of Origin
Developer Certificate of Origin