From 7073bd7d33a90159d84ba00cc748f05ddc58cd86 Mon Sep 17 00:00:00 2001 From: Paolo Melchiorre Date: Thu, 24 Oct 2024 22:30:36 +0200 Subject: [PATCH] Add elapsed time in update index command --- docs/management/commands/update_index.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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." ) )