fix: performance issues for mapping field groups to the Schema #152
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
What does this implement/fix? Explain your changes.
This addresses some performance issues related to mapping the ACF Field Groups to the Schema.
Currently there's logic in place that tries to determine what GraphQL Types in the schema should have a field to access the ACF Field Group from by parsing the field group's "location rules".
This logic is expensive and slow and already runs in the ACF Admin UI when creating/updating field groups, storing the types as the
graphql_typesfield on the ACF Field Group.Instead of running the location mapping at Schema Generation, we should rely on the field groups already defining a "graphql_types" field.
Plugin Build
Here's a built version of the plugin with these changes: wpgraphql-acf.zip
Does this close any currently open issues?
no (issue discussed in Slack)
Any relevant logs, error output, GraphiQL screenshots, etc?
I used an
acf-jsondirectory provided by a user. The config generated 234 Object Types implementing theAcfFieldGroupInterface.Before
Trying to load the GraphQL Schema would take, well, a REALLY long time.
And executing a simple query such as:
{ posts { nodes { id title } } }would also take a LONG time:
😱 😱 😱
AFTER
Now the Schema, with all 234 AcfFieldGroup Types, loads MUCH faster:
And the simple posts query also loads MUCH faster:
Any other comments?
This MIGHT be a breaking change for some users that don't have
graphql_typesdefined on their ACF Field Groups.Need to investigate this a bit more.
For users that have
graphql_typesdefined on their ACF Field Groups this will work already.