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

fix: allCollections query pagination and pagetype timeout errors #1140

Merged
merged 6 commits into from
Feb 21, 2022

Conversation

icazevedo
Copy link
Contributor

What's the purpose of this pull request?

This PR fixes pagination for the allCollections request and also fixes timeouts during pagetype fetching. It also fixes a bug where some products could be ignored during fetching.

How it works?

For fixing pagination, it sends the proper hasNextPage and cursor data with the result.
For fixing timeouts during pagetype fetching, it uses a new DataLoader for pagetypes, which dramatically reduces the total amount of requests being made because of its cache. Also, limits the amount of concurrent pagetype requests being made.

How to test it?

I'll link the base.store PR below

base.store Deploy Preview

TBA

References

We're limiting to 20 concurrent pagetype requests by recommendation from @tlgimenes. The pagination is compliant with Relay's specification.

@icazevedo icazevedo requested a review from tlgimenes February 9, 2022 17:07
@icazevedo icazevedo requested a review from a team as a code owner February 9, 2022 17:07
@icazevedo icazevedo self-assigned this Feb 9, 2022
@netlify
Copy link

netlify bot commented Feb 9, 2022

✔️ Deploy Preview for faststoreui ready!

🔨 Explore the source changes: 6e18a24

🔍 Inspect the deploy log: https://app.netlify.com/sites/faststoreui/deploys/6213a6585a352f00072db77d

😎 Browse the preview: https://deploy-preview-1140--faststoreui.netlify.app

@netlify
Copy link

netlify bot commented Feb 9, 2022

✔️ Deploy Preview for faststore-docs ready!

🔨 Explore the source changes: 6e18a24

🔍 Inspect the deploy log: https://app.netlify.com/sites/faststore-docs/deploys/6213a658947b7a00074aa2d7

😎 Browse the preview: https://deploy-preview-1140--faststore-docs.netlify.app

@icazevedo icazevedo force-pushed the fix/wrong-pagination-and-pagetype-timeouts branch from e51541e to 91e6304 Compare February 9, 2022 17:09
@codesandbox-ci
Copy link

codesandbox-ci bot commented Feb 9, 2022

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.

Latest deployment of this branch, based on commit 6e18a24:

Sandbox Source
Store UI Typescript Configuration

@icazevedo icazevedo changed the title fix: wrong allCollections query pagination and pagetype timeout errors fix: allCollections query pagination and pagetype timeout errors Feb 9, 2022

const loader = (slugs: readonly string[]) => {
return Promise.all(
slugs.map((s: string) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

why not using p-map in here? this way we don't need this Promise.all chained with a map chained with a limit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

p-limit-ing there would allow more than 20 requests to be executed at the same time, and we want to avoid just that.

@icazevedo icazevedo force-pushed the fix/wrong-pagination-and-pagetype-timeouts branch from 2dbe1ce to 8c1f17b Compare February 17, 2022 17:39
@icazevedo icazevedo force-pushed the fix/wrong-pagination-and-pagetype-timeouts branch from eb7d596 to f613efc Compare February 17, 2022 19:10
const pageTypes = await Promise.all(
slugs.map((s) => commerce.catalog.portal.pagetype(s))
const pageTypePromises = await Promise.allSettled(
slugs.map((slugSegment) => pagetypeLoader.load(slugSegment))
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about adding this pagetypeLoader inside the commerce.catalog.portal.pagetype?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't like it. It deviates from what we're currently doing with the SKU and Simulation loaders and couples logic that I think would be good to keep separate.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, lgtm

} = ctx

const result = await commerce.catalog.portal.pagetype(slug)
const result = await pagetypeLoader.load(slug)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not put it inside the commerce.catalog.portal

@tlgimenes
Copy link
Contributor

This PR fixes lots of the issues faced with missing collections. However, there will be still issues. These issues mainly come from the slugify function that we use. We use sindresorhu's slugify function to match what gatsby uses internally. However, pageType api uses the catalog slugify function. Because of how Gatsby works internally, this ambiguity will break some categories. Gatsby v4, however, fixes these issues.

In the future, once we launch Gatsby v4, we can properly fix these other issues.

@tlgimenes tlgimenes merged commit 0150222 into master Feb 21, 2022
@tlgimenes tlgimenes deleted the fix/wrong-pagination-and-pagetype-timeouts branch February 21, 2022 16:20
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.

3 participants