diff --git a/docs/management/commands/update_index.py b/docs/management/commands/update_index.py index 708c75281..937ed4fa8 100644 --- a/docs/management/commands/update_index.py +++ b/docs/management/commands/update_index.py @@ -1,3 +1,5 @@ +import time + from django.core.management.base import BaseCommand from django.db import transaction @@ -5,7 +7,7 @@ class Command(BaseCommand): - @transaction.atomic + def handle(self, *args, **options): """ Update Document's search vector field in an atomic transaction. @@ -13,11 +15,14 @@ def handle(self, *args, **options): Inside an atomic transaction all not null search vector values are set to null and than the field are updated using the document definition. """ - Document.objects.search_reset() - updated_documents = Document.objects.search_update() + _started_at = time.time() + with transaction.atomic(): + Document.objects.search_reset() + updated_documents = Document.objects.search_update() + elapsed = time.time() - _started_at if options["verbosity"] >= 2: self.stdout.write( self.style.SUCCESS( - f"Successfully indexed {updated_documents} documents." + f"Indexed {updated_documents} documents in {elapsed:.03}s." ) )