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

Add tests for maximum database queries #2091

Closed
Tracked by #765
timobrembeck opened this issue Feb 21, 2023 · 0 comments · Fixed by #2175
Closed
Tracked by #765

Add tests for maximum database queries #2091

timobrembeck opened this issue Feb 21, 2023 · 0 comments · Fixed by #2175
Assignees
Labels
🔨 enhancement This improves an existing feature ⁉️ prio: low Not urgent, can be resolved in the distant future. ☺️ effort: low Should be doable in <4h
Milestone

Comments

@timobrembeck
Copy link
Member

Motivation

At the moment, we only check the API result, not the time it takes to generate the correct API result.
It's still part of the manual development/reviewing process to detect changes which drastically decrease API performance.
Usually, database queries are the bottleneck for your API views, especially when some related field is not prefetched etc...

Proposed Solution

Add tests for all API views which define a reasonable maximum of database queries (maybe 10-20, depending on the view) and assert they are not exceeded.
This can be achieved by django_assert_max_num_queries:

def test_max_queries(django_assert_max_num_queries):
    with django_assert_max_num_queries(2):
        Item.objects.create('foo')
        Item.objects.create('bar')
@timobrembeck timobrembeck added ⁉️ prio: low Not urgent, can be resolved in the distant future. 🔨 enhancement This improves an existing feature ☺️ effort: low Should be doable in <4h labels Feb 21, 2023
@timobrembeck timobrembeck added this to the Backlog milestone Feb 21, 2023
@timobrembeck timobrembeck mentioned this issue Feb 21, 2023
33 tasks
@timobrembeck timobrembeck self-assigned this Mar 27, 2023
@timobrembeck timobrembeck modified the milestones: Backlog, 23Q1 Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 enhancement This improves an existing feature ⁉️ prio: low Not urgent, can be resolved in the distant future. ☺️ effort: low Should be doable in <4h
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant