fix(gatsby-source-strapi): nested relation cache invalidation#524
Open
molund wants to merge 2 commits intogatsby-uc:mainfrom
Open
fix(gatsby-source-strapi): nested relation cache invalidation#524molund wants to merge 2 commits intogatsby-uc:mainfrom
molund wants to merge 2 commits intogatsby-uc:mainfrom
Conversation
|
Contributor
|
Thanks for the PR! I'll take a look next week likely or maybe @laurenskling will have time as he's the resident Strapi expert. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Gatsby's cache invalidation for
gatsby-source-strapionly considered the top-levelupdatedAt/publishedAtfields on a Strapi entry. When a nested relation was updated in Strapi, the parent entry's top-level timestamps remained unchanged — causing Gatsby to treat the entry as unmodified and serve stale data.Solution
Added a
findLatestDatesutility to clean-data.js that recursively traverses the entire cleaned entry — including all nested objects and arrays — and returns the maximum updatedAt and publishedAt values found anywhere in the document tree.cleanData now overwrites the top-level updatedAt and publishedAt with these maximums before returning, ensuring that any change to any relation at any depth of nesting will correctly bust the cache.
Compatible with both Strapi v4 and v5 because
findLatestDatesoperates on the output ofcleanAttributes, not on the raw API response.Related Issues
Fixes #523