strawberry-graphql/strawberry-django
N+1 queries due to queryset.count() if cache is empty
开放
#788 创建于 2025年9月30日
enhancementhelp wanted
仓库指标
- 星标
- (496 个星标)
- PR 合并指标
- (PR 指标待抓取)
描述
Describe the Bug
In a nested ListConnectionWithTotalCount, if the child has total_count in the query, if there is a parent node with no related child nodes, there is a queryset.count() triggered. This leads to N+1 queries like scenario if very few parent nodes have child nodes.
Instead, if the queryset is optimized (is_optimized_by_prefetching is True) and there is no offset / limit mentioned then it should just return 0 assuming no nodes were found, calling the count() method only for unoptimized querysets.