question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Avoid calling count unless it is required

See original GitHub issue

It is checking the count for every query, but isn’t using it for anything AFAICT except hasNextPage

DjangoObjectType and DjangoConnectionField

[4.490] SELECT COUNT(*) AS "__count"
FROM "nsproperties_apt"

[0.159] SELECT "nsproperties_apt"."id", ...

This is a massive performance hit on postgresql. If I am selecting only 10 items and I don’t ask for the count then it should not call count. Even if the number of records is < 10 it still calls count.

For hasNextPage you can just iterate one past.

Related to #162 - it would be nice to get totalCount when we need it, but only pay the performance price then.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:7
  • Comments:15

github_iconTop GitHub Comments

6reactions
stale[bot]commented, Sep 6, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

0reactions
stickpersoncommented, Apr 23, 2020

@crucialfelix how do you go about using SimplifiedDjangoConnectionField? I tried using it instead of DjangoFilterConnectionField, so I used DjangoFilterConnectionField instead of DjangoConnectionField. That didn’t work, so I dug into the code a bit and found this bit of code that uses DjangoFilterConnectionField.

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - How to I add to this count without it resetting? Is there ...
Your issue is that the "age" variable will be resetted to 0 every single time the function will be called. The reason for...
Read more >
CA1827: Do not use Count/LongCount when Any can be used
This rule flags the Count and LongCount LINQ method calls used to check if the collection has at least one element. These method...
Read more >
Avoid Using COUNT() in SQL When You Could Use EXISTS()
It depends. If your database supports LIMIT without ORDER BY, then this might be as good as EXISTS. But if ORDER BY is...
Read more >
Make every lead count: Avoiding missed calls, ghost form ...
This process requires at least 5 steps, and that's if everything goes as planned. Not to mention that by the time the employee...
Read more >
Rules for Political Campaign Calls and Texts
In general, robocalls and robotexts to mobile phones require prior consent and ... If the calling party is a business or corporate entity, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found