Skip to content
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions packages/gatsby-source-wordpress/src/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,37 @@ async function fetchData({
}
}
}
// Gravity Forms
if (type == `wordpress__gf_forms`) {
for (let key in routeResponse) {
for (let formKey in routeResponse[key]) {
let form = routeResponse[key][formKey]
if (form && form.id && form.title) {
// Ex. /gf/v2/forms/12
let formUrl = `${url}/${form.id}`
let fetchedData = await fetchData({
route: { url: formUrl, type: `${type}` },
_verbose,
_perPage,
_hostingWPCOM,
_auth,
_accessToken,
})
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we would want to parallelize fetches because right now this would get 1 form data at a time which will slow bootstraping process if there are multiple forms.

Take a look how we pararelize requests in https://github.com/kennethormandy/gatsby/blob/830da2ff03729acaa2267c7cec4110ffd5aeed61/packages/gatsby-source-wordpress/src/fetch.js#L374-L381

(I see that you copied logic from menus fetching - that could also benefit from same treatment if possible)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pieh Thanks for the quick review! I’ve got an attempt at it here, but frankly I don’t think I know async/await well enough to finish it just yet. e1fbf74

I’m also not sure if this approach is totally necessary though, is this outcome that you are looking for? That each property is requested via a URL rather than just doing one request?

=== [ Fetching wordpress__gf_forms ] === http://localhost:8080/wp-json/gf/v2/forms/1/title
=== [ Fetching wordpress__gf_forms ] === http://localhost:8080/wp-json/gf/v2/forms/1/description
=== [ Fetching wordpress__gf_forms ] === http://localhost:8080/wp-json/gf/v2/forms/1/labelPlacement
=== [ Fetching wordpress__gf_forms ] === http://localhost:8080/wp-json/gf/v2/forms/1/descriptionPlacement
=== [ Fetching wordpress__gf_forms ] === http://localhost:8080/wp-json/gf/v2/forms/1/button
=== [ Fetching wordpress__gf_forms ] === http://localhost:8080/wp-json/gf/v2/forms/1/fields
=== [ Fetching wordpress__gf_forms ] === http://localhost:8080/wp-json/gf/v2/forms/1/version
=== [ Fetching wordpress__gf_forms ] === http://localhost:8080/wp-json/gf/v2/forms/1/id
=== [ Fetching wordpress__gf_forms ] === http://localhost:8080/wp-json/gf/v2/forms/1/useCurrentUserAsAuthor
=== [ Fetching wordpress__gf_forms ] === http://localhost:8080/wp-json/gf/v2/forms/1/postContentTemplateEnabled
=== [ Fetching wordpress__gf_forms ] === http://localhost:8080/wp-json/gf/v2/forms/1/postTitleTemplateEnabled
=== [ Fetching wordpress__gf_forms ] === http://localhost:8080/wp-json/gf/v2/forms/1/postTitleTemplate

…rather than now, that does just one request to /forms/1 and then gets all that info. This might be a side effect of me doing something else wrong though.

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant doing parallel requests for forms (not for individual properties of single form)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, that’s what I was aiming to do, but I think I overcomplicated the async/await in an array bit.

entities = entities.concat(fetchedData)
}
}
}
if (_hostingWPCOM) {
// TODO : Need to test that out with Gravity Forms on Wordpress.com hosted site. Need a premium account on wp.com to install extensions. See also ACF options page.
if (_verbose)
console.log(
colorized.out(
`Gravity Forms untested under wordpress.com hosting. Please let me know if it works.`,
colorized.color.Effect.Blink
)
)
}
}
// TODO : Get the number of created nodes using the nodes in state.
let length
if (routeResponse && Array.isArray(routeResponse)) {
Expand Down