paperless-ngx/src/documents/management/commands/document_index.py

27 lines
831 B
Python
Raw Normal View History

from django.core.management import BaseCommand
2020-12-22 13:04:22 +01:00
from django.db import transaction
from documents.tasks import index_optimize
from documents.tasks import index_reindex
2021-02-04 23:40:53 +01:00
class Command(BaseCommand):
2020-10-27 17:08:18 +01:00
help = "Manages the document index."
2020-10-27 17:08:18 +01:00
def add_arguments(self, parser):
2022-02-27 15:26:41 +01:00
parser.add_argument("command", choices=["reindex", "optimize"])
parser.add_argument(
"--no-progress-bar",
default=False,
action="store_true",
2022-02-27 15:26:41 +01:00
help="If set, the progress bar will not be shown",
)
2020-10-27 17:08:18 +01:00
def handle(self, *args, **options):
2020-12-22 13:04:22 +01:00
with transaction.atomic():
2022-02-27 15:26:41 +01:00
if options["command"] == "reindex":
index_reindex(progress_bar_disable=options["no_progress_bar"])
elif options["command"] == "optimize":
2020-12-22 13:04:22 +01:00
index_optimize()