Skip to content
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

Merged
merged 6 commits into from
May 16, 2024

Conversation

gvc
Copy link
Contributor

@gvc gvc commented May 14, 2024

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.

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.
@gvc gvc self-assigned this May 14, 2024
@gvc gvc requested a review from a team as a code owner May 14, 2024 17:55
@gvc gvc requested review from renatamottam and lucasfp13 and removed request for a team May 14, 2024 17:55
Copy link

vercel bot commented May 14, 2024

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

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
faststore-site ⬜️ Ignored (Inspect) Visit Preview May 16, 2024 5:36pm

Copy link
Member

@eduardoformiga eduardoformiga left a 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 🎉

Copy link

codesandbox-ci bot commented May 15, 2024

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.

Copy link
Member

@eduardoformiga eduardoformiga left a 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.

Copy link
Member

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)

Comment on lines +48 to +58
/*
* 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
*/
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!

@gvc gvc merged commit f783663 into main May 16, 2024
7 checks passed
@gvc gvc deleted the fix/multiple-pages-loading branch May 16, 2024 18:50
@eduardoformiga eduardoformiga restored the fix/multiple-pages-loading branch May 22, 2024 18:08
eduardoformiga added a commit that referenced this pull request May 24, 2024
## 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants