Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add elapsed time in update index command #1695

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions docs/management/commands/update_index.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
import time

from django.core.management.base import BaseCommand
from django.db import transaction

from ...models import Document


class Command(BaseCommand):
@transaction.atomic

def handle(self, *args, **options):
"""
Update Document's search vector field in an atomic transaction.

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."
)
)