Skip to content

Commit 021b2fb

Browse files
authored
Add elapsed time in update index command (#1695)
1 parent 5eee653 commit 021b2fb

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
1+
import time
2+
13
from django.core.management.base import BaseCommand
24
from django.db import transaction
35

46
from ...models import Document
57

68

79
class Command(BaseCommand):
8-
@transaction.atomic
10+
911
def handle(self, *args, **options):
1012
"""
1113
Update Document's search vector field in an atomic transaction.
1214
1315
Inside an atomic transaction all not null search vector values are set
1416
to null and than the field are updated using the document definition.
1517
"""
16-
Document.objects.search_reset()
17-
updated_documents = Document.objects.search_update()
18+
_started_at = time.time()
19+
with transaction.atomic():
20+
Document.objects.search_reset()
21+
updated_documents = Document.objects.search_update()
22+
elapsed = time.time() - _started_at
1823
if options["verbosity"] >= 2:
1924
self.stdout.write(
2025
self.style.SUCCESS(
21-
f"Successfully indexed {updated_documents} documents."
26+
f"Indexed {updated_documents} documents in {elapsed:.03}s."
2227
)
2328
)

0 commit comments

Comments
 (0)