Skip to content

Commit c5d3d5b

Browse files
committed
Linting
1 parent 6a6cde2 commit c5d3d5b

File tree

3 files changed

+12
-22
lines changed

3 files changed

+12
-22
lines changed

tests/performance/perftest/models.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from django.db import models
22

3-
from django_mongodb_backend.fields import EmbeddedModelArrayField, EmbeddedModelField, ObjectIdField
3+
from django_mongodb_backend.fields import EmbeddedModelArrayField, EmbeddedModelField
44
from django_mongodb_backend.models import EmbeddedModel
55

66

@@ -25,7 +25,6 @@ class Meta:
2525
]
2626

2727

28-
2928
class ForeignKeyModel(models.Model):
3029
name = models.CharField(max_length=100)
3130

tests/performance/perftest/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
For the full list of settings and their values, see
1010
https://docs.djangoproject.com/en/5.2/ref/settings/
1111
"""
12+
1213
import os
1314
from pathlib import Path
1415

@@ -68,7 +69,7 @@
6869
# }
6970

7071
settings = django_mongodb_backend.parse_uri(
71-
f"mongodb://localhost:27017/benchmarking",
72+
"mongodb://localhost:27017/benchmarking",
7273
)
7374
DATABASES = {
7475
"default": settings,

tests/performance/perftest/tests.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import json
2525
import os
26-
import random
2726
import time
2827
import unittest
2928
import warnings
@@ -52,13 +51,9 @@
5251
MAX_ITERATION_TIME = 10
5352
NUM_DOCS = 1000
5453
else:
55-
NUM_DOCS = 1_000_000
56-
NUM_ITERATIONS = 1
57-
MIN_ITERATION_TIME = 1
58-
# NUM_ITERATIONS = 10
59-
# MIN_ITERATION_TIME = 30
60-
MAX_ITERATION_TIME = 1
61-
# NUM_DOCS = 10000
54+
NUM_ITERATIONS = 10
55+
MIN_ITERATION_TIME = 30
56+
NUM_DOCS = 10000
6257

6358
TEST_PATH = os.environ.get("TEST_PATH", Path(os.path.realpath(__file__)).parent.parent / "odm-data")
6459

@@ -372,8 +367,7 @@ def setUp(self):
372367
super().setUp()
373368
self.create_model()
374369
self.ids = [
375-
model.embedded_str_doc_array[0].id
376-
for model in list(LargeNestedModel.objects.all())
370+
model.embedded_str_doc_array[0].id for model in list(LargeNestedModel.objects.all())
377371
]
378372

379373
def do_task(self):
@@ -384,6 +378,7 @@ def tearDown(self):
384378
super().tearDown()
385379
LargeNestedModel.objects.all().delete()
386380

381+
387382
class TestSmallFlatDocFilterByIn(SmallFlatDocTest, TestCase):
388383
def setUp(self):
389384
super().setUp()
@@ -397,37 +392,33 @@ def setUp(self):
397392
self.ids = [model.field1 for model in inserted]
398393

399394
def do_task(self):
400-
print(SmallFlatModel.objects.filter(field1__in=[self.ids[0]]).explain())
401395
for _id in self.ids:
402396
list(SmallFlatModel.objects.filter(field1__in=[_id]))
403397

404398
def tearDown(self):
405399
super().tearDown()
406400
SmallFlatModel.objects.all().delete()
407401

402+
408403
class TestSmallFlatDocFilterPkByIn(SmallFlatDocTest, TestCase):
409404
def setUp(self):
410405
super().setUp()
411406
self.ids = []
412407
models = []
413-
fields = [str(ObjectId()) for _ in range(NUM_DOCS // 10)]
414408
for doc in self.documents:
415409
models.append(SmallFlatModel(**doc))
416410

417-
for model in models:
418-
model.field1 = fields[random.randint(0, len(fields) - 1)]
419-
420411
SmallFlatModel.objects.bulk_create(models)
421-
self.ids = random.sample(fields, len(fields) // 10)
422-
# print(SmallFlatModel.objects.filter(id__in=[self.ids[0]]).explain())
412+
self.ids = [model.id for model in models]
423413

424414
def do_task(self):
425-
list(SmallFlatModel.objects.filter(field1__in=self.ids))
415+
list(SmallFlatModel.objects.filter(id__in=self.ids))
426416

427417
def tearDown(self):
428418
super().tearDown()
429419
SmallFlatModel.objects.all().delete()
430420

421+
431422
class TestLargeFlatDocFilterPkByIn(LargeFlatDocTest, unittest.TestCase):
432423
def setUp(self):
433424
super().setUp()
@@ -436,7 +427,6 @@ def setUp(self):
436427
models.append(LargeFlatModel(**doc))
437428
LargeFlatModel.objects.bulk_create(models)
438429
self.id = LargeFlatModel.objects.first().id
439-
print(LargeFlatModel.objects.filter(id__in=[self.id]).explain())
440430

441431
def do_task(self):
442432
list(LargeFlatModel.objects.filter(id__in=[self.id]))

0 commit comments

Comments
 (0)