- Notifications
You must be signed in to change notification settings - Fork302
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Status quo Scenario: No include parameter Solution: No include paramter defget_queryset(self):qs=super().get_queryset()include=self.request.GET.get("include",None)ifnotincludeor"fieldName"notininclude:qs=qs.prefetch_related(Prefetch("field_name",queryset=Model.objects.only('id'))returnqs Without the But there is another point. The code below prefetches in any case. But if the api is called withsparse fieldsets and the related field is not part of the request, the prefetching is not needed. So it need another logic to get the fields parameters and analyze them against the prefetching logic. Something like: fields=self.request.GET.get("fields[ResourceName]","").split(',')iffieldsand"fieldName"infields:# do prefetchingelse:# do not add default prefetching So i think this is a general problem which hits every view with a |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 1 comment
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Thanks for bringing this up again. Indeed the prefetching implementation does not cover all use cases. There has been a discussion at#921 about it and also an attempt to implement it at#964 but got never finished. I am very open for improvements in this area but to get this right we most likely need a different approach as suggested in the above discussion than the two mixins we already have for this. |
BetaWas this translation helpful?Give feedback.