-
Notifications
You must be signed in to change notification settings - Fork 83
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
Prefetching for generic relations does not seem to work #75
Comments
Maybe this is related to #45? |
Hi @crazyscientist ! The detection of foreign key id is done manually by using graphene-django-optimizer/graphene_django_optimizer/query.py Lines 321 to 326 in e5c57fc
GenericForeignKey to the detection. If that works, feel free to create a PR together with a test for the GenericForeignKey case.
|
Looking into this a little bit deeper, I think it would require some changes to the code to support this properly. At the time I made this, I only had a few generic relations in the codebase I was applying this library. But if a codebase has many fields like that, I see the value that solving this issue would provide. If you have the time, feel free to create a PR. Will gladly review it. |
Hi there,
first of all, thanks for the project, and I'd like to point out that prefetching works for
ForeignKey
andManyToMany
relations. Somehow onlyGenericForeignKey
is not recognized as optimizable.Versions
Models
Schema
Query
Problem
For non-generic relations the optimization works as expected, but with a generic relation (in the above example:
comments
) it does not. Based on the raw SQL queries executed, it looks like for every incident the comments are queried and for each comment the relatedUser
model is queried.Expected
Generic relations are tough. Django allows prefetching of the model that is a member of the generic relation, but nothing further, e.g.:
It would be unfair to expect that the optimizer overcomes this limitation of Django. It would be really great, if the optimizer could prefetch the comments in this example.
The text was updated successfully, but these errors were encountered: