Skip to content
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

Refactor QuerySet count() calls #283

Open
matthewcornell opened this issue Dec 8, 2020 · 0 comments
Open

Refactor QuerySet count() calls #283

matthewcornell opened this issue Dec 8, 2020 · 0 comments

Comments

@matthewcornell
Copy link
Member

COUNT(*) statements are expensive in postgres, so we should consider refactoring QuerySet count() calls (which do COUNT under the hood). Esp. in these cases, we basically double the execution time by first calling count() and then the query itself:

  • query_forecasts_for_project()
  • query_scores_for_project()
  • query_truth_for_project()

A better approach is to replace calling count() with simply iterating over the results, counting along the way, and terminating if the max is reached, making sure to call iterator() so that the server-side cursor (2000-rows chunks by default) is active - see [Change QuerySet calls to use iterator() #282].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant