n+1 queries in execution dataloader docs
See original GitHub issue- What is the current behavior?
https://github.com/graphql-python/graphene/blame/master/docs/execution/dataloader.rst#L57-L58
>>> users = {user.id: user for user in User.objects.filter(id__in=keys)}
>>> print(users)
{1: <User: Tom>, 2: <User: Frank>, ...}
Database is hit once for each user.
- What is the expected behavior?
>>> user_ids = User.objects.filter(id__in=keys).values_list('id', flat=True)
>>> users = User.objects.in_bulk(user_ids)
>>> print(users)
{1: <User: Tom>, 2: <User: Frank>, ...}
A single query can be used to fetch all user IDs and users
- What is the motivation / use case for changing the behavior?
Performance
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Solving N+1 in GraphQL Python With Dataloader - Jerry Ng
Tips and guide to handle N+1 problem with Dataloader in Django Graphene while developing GraphQL API in Python.
Read more >GraphQL/Graphene: How to Solve the N+1 Problem With ...
Learn how to avoid one of the most common GraphQL performance pitfalls: the N+1 problem, in this deep dive by Cloud Academy engineer, ......
Read more >Batching – A powerful way to solve N+1 queries every Rubyist ...
In this post I'm going to tell you about batching as a technique to help avoid N+1 queries, existing battle-tested tools like Haskell...
Read more >How Federation handles the N+1 query problem
In a monolithic GraphQL server, the execution engine takes these steps: Resolve the Query.topReviews field, which returns a list of Review s.
Read more >Query optimization - Prisma
This guide describes ways to optimize query performance, debug performance issues, and how to tackle common performance issues such as the ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Closing out this issue. Using graphene 2.x and having inconsistent results. Will test further when we upgrade.
@nickvellios I’m not sure what you mean. Running
User.objects.filter(id__in=keys)
should only execute 1 db query. Are you seeing something different?