diff --git a/src/documents/tests/test_api_objects.py b/src/documents/tests/test_api_objects.py index 0cdf20dc2..56a2829b2 100644 --- a/src/documents/tests/test_api_objects.py +++ b/src/documents/tests/test_api_objects.py @@ -840,7 +840,7 @@ class TestBulkEditObjects(APITestCase): "change": {"users": [self.user1.id], "groups": [group1.id]}, } - def run_with_n_tags(n: int) -> int: + def run_with_n_tags(n: int, *, capture: bool = True) -> int | None: tags = [Tag.objects.create(name=f"perm-tag-{n}-{i}") for i in range(n)] with CaptureQueriesContext(connection) as ctx: response = self.client.post( @@ -860,7 +860,13 @@ class TestBulkEditObjects(APITestCase): for tag in tags: self.assertEqual(get_users_with_perms(tag).count(), 2) self.assertEqual(get_groups_with_perms(tag).count(), 1) - return len(ctx.captured_queries) + return len(ctx.captured_queries) if capture else None + + # Warm up any one-time, process/instance-cached lookups (e.g. Django's + # ContentType cache) on the same code path before measuring, so the + # comparison below isn't skewed by whichever of the two calls happens + # to pay a cold-cache cost that has nothing to do with tag count. + run_with_n_tags(1, capture=False) small_batch_queries = run_with_n_tags(5) large_batch_queries = run_with_n_tags(50)