-
-
Notifications
You must be signed in to change notification settings - Fork 117
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
Nested Perms Results in unecessary queries (N+1?) #499
Comments
this may be a more performant workaround @strawberry_django.field(
annotate={
"_private_details": lambda info: Case(
When(
Exists(
filter_for_user(
models.Note.objects.all(),
info.context.request.user,
[PrivateNotePermissions.VIEW],
)
),
then=F("private_details"),
),
default=Value(None),
),
}
)
def private_details(self, root: models.Note) -> Optional[str]:
return root._private_details |
Hey @vecchp , The main difference between the 2 codes is that in the first one you are checking for This is a similar issue to #337 in which the optimizer is not currently able to optimize some more complex nested lists/connections, specially when they are using pagination, filtering, permissioning (like this), etc Thanks for reporting this! I'll soon try to take a look at that nested issue and will try to solve this issue together :) |
Seems like a similar library for graphene has worked around this issue. At least with nested queries maybe unrelated to perms. MrThearMan/graphene-django-query-optimizer#62 |
Hrmm thanks for linking those :), I'll take a look at that for inspiration! |
Describe the Bug
Nesting permissions i.e
private_details
checked byHasSourcePerm
yields unnecessary queries that could be optimized. Current code yields 6 queries, while the workaround below results in 2.Additional Context
Workaround
Upvote & Fund
The text was updated successfully, but these errors were encountered: