-
-
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
Query optimizer doesn't work with relay connection #337
Comments
This issue is the same as #340 . This is happening because the optimizer currently is skipping any nested connections: https://github.com/strawberry-graphql/strawberry-graphql-django/blob/main/strawberry_django/optimizer.py#L320C29-L320C29 I'll try to create a meta issue about this to discuss how we can properly optimize nested connections. Because right now, since the nested query will be sliced, trying to optimize it will do the opposite of what we want the optimizer to do, which is do an extra prefetch without limit/offset. |
@jlgonzalez-martinez as I mentioned in this comment, I just noticed that you are also doing a For the reasons I mentioned there, can you test without it to see if it does work correctly? |
@bellini666 suggested this while on a call :D WITH numbered_rows AS (
SELECT
"_FilmToSpecies"."A" AS "_prefetch_related_val_a_id",
"Species"."id",
"Species"."name",
ROW_NUMBER() OVER (
PARTITION BY "_FilmToSpecies"."A"
ORDER BY "Species"."id"
) row_num
FROM "Species"
INNER JOIN "_FilmToSpecies"
ON ("Species"."id" = "_FilmToSpecies"."B")
WHERE "_FilmToSpecies"."A" IN ('1', '2', '3')
)
SELECT "_prefetch_related_val_a_id", "id", "name" FROM numbered_rows WHERE row_num <= 10; |
@patrick91 wow, was testing here and just noticed that Django 4.2+ actually does this window function filtering when you slice a prefetch. e.g. SomeModel.objects.prefetch_related(
Prefetch(
"some_relation",
queryset=SomeRelation.objects.all()[:10],
)
) It will use the |
Hi, |
@stygmate Thiago is working on adding support for this, hopefully we get it soon 😊 |
Describe the Bug
Example project could be found here.
The problem is that uncomment the students that use
ListConnectionWithTotalCount
and comment the other one seems to not optimize automatically. I try to put a specific prefetch in the connection but then don't optimize inner fields.System Information
Additional Context
types.py
Upvote & Fund
The text was updated successfully, but these errors were encountered: