-
Notifications
You must be signed in to change notification settings - Fork 63
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
Fetch multiple CMS template pages instead of just the first #2314
Conversation
Currently, when trying to load contentTypes from the Headless CMS we just fetch the first page and ignore the hasNextPage response from the cmsClient. This PR changes that to load all publishedContentTypes before returning. This might be troublesome if a given account has thousands of content types of the same type (PLP, for instance). We can either increase the page size to make fewer requests or investigate if we can move the filtering to the CMS Client.
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! thanks for adding tests 🎉
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice improvements with cache and Promise.all
, @gvc ! ⭐
the test need to be updated but I'll let it pre approved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to update the tests after update the function (https://github.com/vtex/faststore/actions/runs/9103665826/job/25025988818?pr=2314)
/* | ||
* This in memory cache exists because for each page (think category or department) | ||
* we are fetching all the pages of the same content type from the headless CMS to | ||
* find the one that matches the slug. | ||
* | ||
* So instead of making multiple request for the Headless CMS API for each page we make | ||
* one for each content-type and reuse the results for the next page. | ||
* | ||
* Since we rebuild on a CMS publication the server will go away and will "invalidate" | ||
* the cache | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
From my understanding, for each kind of PLP, the cache will be leveraged, right? 10/10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes!
## What's the purpose of this pull request? Reverts the cache approach when fetching multiple hCMS pages. It looks like the cache strategy used in this PR - #2314 It is bringing some issues for clients. So This PR aims to revert this logic.
What's the purpose of this pull request?
Currently, when trying to load contentTypes from the Headless CMS we just fetch the first page and ignore the hasNextPage response from the cmsClient.
How it works?
This PR changes that to load all publishedContentTypes before returning. This might be troublesome if a given account has thousands of content types of the same type (PLP, for instance). We can either increase the page size to make fewer requests or investigate if we can move the filtering to the CMS Client.
How to test it?
I've added tests, but this can be replicated by copying the
server/cms/index.ts
code to a store's node_modules folder and you should see the effect.