Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Addingprefetch_for_fields andselect_for_fields#1159

Nekidev started this conversation inIdeas
Discussion options

At the moment, we haveselect_for_includes andprefetch_for_includes for dynamic prefetching and selecting. I was wondering if there is anything similar for thefields[resource] parameter (I believe there is not) since I'm adding some metadata to my resources:

{...,"meta": {"user": {"liked":true,"saved":false        }    }}

In this case, I make a new DB query on every resource that the API returns, since this requires checking if the resource is in the user's library. This query can be omitted if the user is not logged in or the request hasfields[resource] withoutuser as a query parameter, but I'd like to prefetch the related resources only if the field is present.

ATM, I need to decide whether to prefetch all the users or none of them and make an extra query. Is there any way to accomplish this or not?

My suggestion in case this is not yet possible is to add aprefetch_for_fields andselect_for_fields which would work exactly as the currentprefetch_for_fields andselect_for_fields.

Note: After writing this I realized I can avoid making a new DB query usingvalues_list.

You must be logged in to vote

Replies: 1 comment

Comment options

Prefetching is a topic which needs to be improved within DJA however it is also not an easy task. Best take a look at discussion#921 to see what approaches are being discussed, and there are also some code bits and PRs referenced.

My feeling is that we should make auto prefetching as best as possible. But when it cannot cover what is needed, it should be possible to simply disable it and a DJA user can then do their own optimization within their code (like overwritingget_queryset and do the prefetches there.)

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Ideas
Labels
None yet
2 participants
@Nekidev@sliverc

[8]ページ先頭

©2009-2025 Movatter.jp