-
Notifications
You must be signed in to change notification settings - Fork 466
perf: Expose graphql_should_analyze_queries as setting
#3008
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
perf: Expose graphql_should_analyze_queries as setting
#3008
Conversation
fe8a90c to
8452be8
Compare
|
I like this! I thought this was |
|
Ok, so this will technically be a breaking change as this feature is needed for folks that are querying via GET and have a caching client (Varnish, etc) or otherwise doing something with the headers that are returned by X-GraphQL-Keys. . .or when folks are using POST requests and have WPGraphQL Smart Cache object cache enabled. Before merging this, we need to make sure WPGraphQL Smart Cache ensures QueryAnalyzer is "ON" for GET requests or when GraphQL Object cache is available. If that's not already enforced by WPGraphQL Smart Cache, we need to make sure it is and communicate well that WPGraphQL Smart Cache users NEED to update to the version that does that before updating WPGraphQL to the version that switches the default to "OFF" |
|
@justlevine lol, after writing my comment above, I realized you already called this out: 🤦🏻♂️ |
@jasonbahl sure, but I wasn't as detailed, and seeing it written out makes me worry about the compatibility for non-Smart Cache solutions (this would be a patch change in Smart Cache, so anyone with autoupdates enabled would get both updates and keep compatibility seamless). Perhaps as a way to preserve back-compat, we can expose this as a setting and only default it to |
@justlevine this seems sensible to me |
8452be8 to
8e9ce6a
Compare
graphql_should_analyze_queries value to GraphQL Debugging statusgraphql_should_analyze_queries as setting and default to off on new installs
|
@jasonbahl Changes made and the PR description updated with the specifics of the new implementation. I still need to update/add the corresponding WPUnit tests, but in the interim please let me know if you like the new proposed solution. |
Set default value for get_option
@justlevine ya, this looks good! Thanks 🙏🏻 |
|
Tests added - @jasonbahl I believe this is ready for merge 🤞 |
activation.php
Outdated
| } | ||
|
|
||
| // Run any activation scripts before updating the version. | ||
| graphql_migrate_1_20_0(); |
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.
Does this run for folks that update via composer too? 🤔
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.
Now that you mention it it might not even work on plugin update and only on actual activation. 🤦
Not sure the best approach here:
- If it's non-composer, we could conditional it as a run_once on
admin_init, but someone updating via composer would still need to log in. - Or we absorb the db version check on every
init, the extra potential hit is annoying, but still less than with QA activated. - Or we just keep the setting and filter logic, and wait until 2.0 to switch the the default behavior to
off.
@jasonbahl thoughts?
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.
@justlevine perhaps in the is_enabled_for_query we can add some logic to handle folks that might not have triggered the migrate script.
Like, when we determine if GRAPHQL_DEBUG is enabled, etc. . .
If we are able to determine no value has been set in the db for query_analyzer_enabled we can assume the migrate script hasn't run and/or the user hasn't manually saved the settings yet, so we can have some logic there to compensate for users that didn't trigger the migrate script?
|
Code Climate has analyzed commit 8ee0e4c and detected 2 issues on this pull request. Here's the issue category breakdown:
View more on Code Climate. |
graphql_should_analyze_queries as setting and default to off on new installsgraphql_should_analyze_queries as setting
|
Scope of this PR was reduced to just exposing the toggle/filters/method calls. A mechanism for updating old DB values on migration will be evaluated/handled independently, to avoid the risks of tech debt by having the solution coupled too deeply to this PR's use case. @jasonbahl ready for your review again 🤞 |
|
@justlevine looks good. I'll open a corresponding Issue and PR to handle enabling when WPGraphQL Smart Cache is active. |
|
@justlevine fwiw wp-graphql/wp-graphql-smart-cache#268 While the default will be "on" as of this PR, since it can easily be checked "off" I opened this issue for WPGraphQL Smart Cache to make it more difficult to turn of the analyzer as it would have negative impact for WPGraphQL Smart Cache users if it were disabled. |


What does this implement/fix? Explain your changes.
This PR adds an admin setting for enabling/disabling the Query Analyzer, and defaults the setting value to
offon new installs, unless GraphQL Debugging is enabled. In other words by default, the QueryAnalyzer will only be enabled when GraphQL Debugging is also enabled.The reason for this is the overhead caused by having QueryAnalyzer enabled. While this cost is justified during debugging, or when needed to cache future responses, on vanilla WPGraphQL setups there is no need to pay for that extra processing.
More specifically:
query_analyzer_enabledsetting to the WPGraphQL Settings page. The setting control is disabled ifGraphQL::debug()is true.QueryAnalyzer::is_enabled()static method that can be used to check whether the QA is disabled site wide. The return value in order of priority is:truegraphql_should_analyze_queriesfilter.QueryAnalyzer::is_enabled_for_query()instance method that uses a newgraphql_should_analyze_queryfilter which passes the\WPGraphQL\Requestobject as a parameter, and can be used to enable/disable the QueryAnalyzer for specific requests.query_analyzer_enabledvalue oftruefor existing WPGraphQL installs on upgrade, to prevent back-compat issues.response.extensionsnow requires bothQueryAnalyzer::is_enabled_for_query()and\WPGraphQL::debug()to be true.Does this close any currently open issues?
Related #1873
Any relevant logs, error output, GraphiQL screenshots, etc?
Per the below screenshots TTFB decreased from
165.68ms=>125.93mson a simple query with very few types to analyze.Before (Query Analyzer enabled by default)
After (Query Analyzer disabled by default)
Settings toggle:
GraphQL Debugging enabled

GraphQL Debugging disabled

Any other comments?
Important
Plugins that rely on the Query Analyzer should update their code with
add_action( 'graphql_should_analyze_queries', true );or do a check around theQueryAnalyzer::is_enabled()method.I went with a Setting Label of
Enable GraphQL Type Tracking, since "Query Analyzer" is the internal feature name, and not self-documenting for end users.Made the assumption that this will be part of the 1.20.0 release. If not the
activation.phpmethod should be updated.The future potential of
graphql_should_analyze_queryshould make it easier to exclude or set custom rules around caching specific types/models/or even named queries.Where has this been tested?
Operating System: Ubuntu 20.04 (wsl2 + devilbox + 8.1.15)
WordPress Version: 6.4.2