Closed SupImDos closed 4 months ago
a) Configurably force the optimiser to never use select_related, only prefetch_related
A config for that, which can be used both globally and per-field, sounds interesting...
b) Have the optimiser detect when a type has a custom get_queryset, and use prefetch_related instead of select_related
The optimizer will probably have to have a way to detect when to fallback to prefetch_related
for cases like https://github.com/strawberry-graphql/strawberry-django/issues/549
A custom get_queryset
might indeed indicate a second need for this, indeed.
Would you say that by doing this, it solves any problems you have here? Or would you still need the option? Because I'm thinking about going this way, which will solve 2 issues at once, and avoid having to add an extra option that is probably not going to be needed.
The optimizer will probably have to have a way to detect when to fallback to
prefetch_related
for cases like #549A custom
get_queryset
might indeed indicate a second need for this, indeed.Would you say that by doing this, it solves any problems you have here? Or would you still need the option? Because I'm thinking about going this way, which will solve 2 issues at once, and avoid having to add an extra option that is probably not going to be needed.
Yes, I think so. As you suggest, falling back to .prefetch_related
when a type has a custom get_queryset
would solve my problem and seems to be a better approach than adding another option 😁
Hi!
I need to override the base
get_queryset
method of all of my types due to a pre-existing approach to multi-tenancy and permissions. This means my relations can only ever be resolved correctly withprefetch_related
(at the cost of extra queries) and not withselect_related
which bypasses the custom querysets.Currently, the
DjangoOptimizerExtension
always usesselect_related
for non-listForeignKey
relations, regardless of whether there is a customget_queryset
defined on the type.I'm wondering if there's a way to either:
a) Configurably force the optimiser to never use
select_related
, onlyprefetch_related
b) Have the optimiser detect when a type has a customget_queryset
, and useprefetch_related
instead ofselect_related
Describe the Bug
Here is a contrived example:
With the above, a query such as:
Results in the following single database query, using
select_related
- which is missing the filtering on the nested regions:Whereas my desired behaviour would be two database queries, using
prefetch_related
:System Information
Additional Context
DjangoOptimizerExtension
562
549
Upvote & Fund