-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
feat(gatsby-source-contentful): move types into createSchemaCustomization #33207
Conversation
const fetchData = require(`./fetch`) | ||
const { createPluginConfig } = require(`./plugin-options`) | ||
|
||
export async function onPreBootstrap( |
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.
@wardpeet we would want to make sure with v4 that this function is onPluginInit
. Otherwise the workers with source nodes and createSchemaCustomization will have the wrong data, correct?
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.
It does a lot of tricky things that I don't understand why we're doing it in onPreBootstrap or would even do it in onPluginInit.
Why are we fetching data here?
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, if you don't call this code, you will stay with the old Contentful data
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 understand but why can't we put this all in sourcenodes? This makes it super complex, I don't even understand what's happening here 😬
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.
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.
It might be possible to split up the huge fetch function into two functions:
createSchemaCustomization
will load content types
sourceNodes
will load content types + all of the rest
Loading data twice is bad, thats why I originally moved all of this into bootstrap. Could work around this with the Gatsby cache, but only if I can rely on the call order of createSchemaCustomization
&& sourceNodes
WDYT?
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.
Why can't we call contentTypes separate from data? Doesn't contentful supports that? Relying on cache will be problematic when the process crashes - you don't really know where we left off.
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.
We can, it is supported. I just wonder If i can avoid calling contentTypes twice.
Will try it now, let u know where I end up :)
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.
GATSBY_CONTENTFUL_EXPERIMENTAL_FORCE_CACHE
is going to make it tricky, as it assumes we have all the data in one place which will not be true anymore.
I might store the content type information in a separate file 🤔
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 got a variant working in e2e and manual tests. Unit tests are green except the huge snapshot based tests. Will fix these after lunch, then we should be able to do another review round :)
I split up the fetching and processing of content types from the rest of the data we get from Contentful.
|
Thank you for the detailed walk through of the changes, that really helps to follow what's happening.
I think the following comment from @wardpeet sums this up
I'm still a little fuzzy as to what this experimental force cache does and what the purpose of it is? Is this a feature that people actually use? |
The experimental force cache was a way to bypass the sourcing step. It was primarily used internally when working with customers with really large datasets. It was always undocumented / experimental. I think the customer success team was the primary user of that flag, and we aren't actively using it anymore. I'm fine with removing it. |
Alright, then I'll request the content types twice from Contentful. As this is only a minimal amount of data compared to the actual content, we should not add to much overhead. |
I updated the code to request fresh content type data for every node sourcing and schema customization and updated my comment above to reflect the new flow. |
a607dd1
to
80f3df8
Compare
573bc2b
to
97cacdf
Compare
Why refetch content types for every sourcing? Is that needed? I assume this would slow down inc builds? |
That was my first approach. But Daniel and Ward say storing the content types in cache is not save? #33207 (comment) I can still revert/remove 59af410 to use Gatsby cache for storing the content types |
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.
Added questions and comments. There are some possible race conditions with cache & node store
reporter, | ||
}) | ||
|
||
createTypes(` |
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.
@vladar is it faster to only run createTypes once vs many times or are things the same?
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.
packages/gatsby-source-contentful/src/create-schema-customization.js
Outdated
Show resolved
Hide resolved
packages/gatsby-source-contentful/src/create-schema-customization.js
Outdated
Show resolved
Hide resolved
packages/gatsby-source-contentful/src/create-schema-customization.js
Outdated
Show resolved
Hide resolved
packages/gatsby-source-contentful/src/create-schema-customization.js
Outdated
Show resolved
Hide resolved
…ization and node sourcing
…operly add enableTags
…a customization and node sourcing" This reverts commit 59af410.
Co-authored-by: Ward Peeters <ward@coding-tech.com>
f49eaf9
to
4f22ccf
Compare
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.
If tests are green, let's get this in! 🚢 Thanks a ton @axe312ger
…tion (gatsbyjs#33207) Co-authored-by: Ward Peeters <ward@coding-tech.com>
…tion (#33207) Co-authored-by: Ward Peeters <ward@coding-tech.com>
This bit me today when I wanted to use it. Apparently `forceFullSync` was removed years ago. PR's: gatsbyjs#33238, gatsbyjs#33207 @axe312ger mentioned he'd remove it in the new version, but since that's not live yet I'm proposing it here.
… from readme (#38787) * Remove `forceFullSync` option from readme This bit me today when I wanted to use it. Apparently `forceFullSync` was removed years ago. PR's: #33238, #33207 @axe312ger mentioned he'd remove it in the new version, but since that's not live yet I'm proposing it here. * remove option from create-gatsby as well --------- Co-authored-by: Michal Piechowiak <misiek.piechowiak@gmail.com>
Replacement of #32351
GATSBY_CONTENTFUL_EXPERIMENTAL_FORCE_CACHE
got removedforceFullSync
removed as it wasn't supported for a while and addedenableTags
to validationcleanup: enable typescript check and move to import syntax(moved to chore(gatsby-source-contentful): clean up code base and introduce es-module syntax #33213)feature: improve logging by separating logs for new and updated entities(moved to chore(gatsby-source-contentful): clean up code base and introduce es-module syntax #33213)