Closed sathyapulse closed 1 month ago
The slow query is generated in the line /src/Data/Loader/UserLoader.php#L82.
Wondering if we even need to do a direct query here over something built-in (and possibly pre-cached), and if we do need our own why we're not caching it ourselves 🤔
@sathyapulse thanks for reporting! I know we had explored this issue in the past and had made some progress, but perhaps not enough progress.
Going to link some things for reference:
@sathyapulse I've opened this PR: https://github.com/wp-graphql/wp-graphql/pull/3183
Would love to hear from you after you have a chance to test it to see how it impacts your use cases.
Description
We have encountered a customer issue where the GraphQL endpoints were returning slow responses. When debugging the problem, we found the User Loader generates a slow query to determine if the user is public.
The slow query is generated in the line /src/Data/Loader/UserLoader.php#L82.
In this case, the query scans 258K rows and takes 8-10 seconds to execute.
The slow query could be optimised with the query below, which returns results in 2 milliseconds.
If you look at the
EXPLAIN
, it scans only 14K rows to fetch the results.The current query returns the user ID even when the user doesn't exist in the database. The new query returns the user ID only when the user exists in the database. I also removed the unnecessary
LIMIT
from the query.Could you please patch the plugin with the optimised query? I'm happy to help with testing or answer any questions.
Steps to reproduce
The issue can be reproduced from the GraphiQL IDE with the query below.
Additional context
No response
WPGraphQL Version
1.22.1
WordPress Version
6.4.5
PHP Version
8.1
Additional environment details
I tested this in the older WordPress and plugin versions, but I'm sure it can also be reproducible in the latest versions.
Please confirm that you have searched existing issues in the repo.
Please confirm that you have disabled ALL plugins except for WPGraphQL.