-
Notifications
You must be signed in to change notification settings - Fork 415
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(audit_log): Prefetch Fk relations to avoid n+1 (#197)
* fix(audit_log): Prefetch Fk relations to avoid n+1 Closes: #174 * test(audit_logs): Add test to check the number of query executed The test will make sure that we are not executing more than 2 queries in the API(one for the result and the other one for pagination) * !fixup: inspect the response to check the count
- Loading branch information
1 parent
8f0578f
commit 1d54c2f
Showing
2 changed files
with
17 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from django.urls import reverse | ||
from rest_framework import status | ||
|
||
|
||
def test_audit_logs_only_makes_two_queries( | ||
admin_client, project, environment, django_assert_num_queries | ||
): | ||
url = reverse("api-v1:audit-list") | ||
|
||
with django_assert_num_queries(2): | ||
res = admin_client.get(url, {"project": project}) | ||
|
||
assert res.status_code == status.HTTP_200_OK | ||
assert res.json()["count"] == 1 |