2020-10-25 23:03:02 +01:00
|
|
|
from django.core.management import BaseCommand
|
2020-12-22 13:04:22 +01:00
|
|
|
from django.db import transaction
|
2023-04-20 08:10:17 -07:00
|
|
|
|
2022-03-11 10:55:51 -08:00
|
|
|
from documents.tasks import index_optimize
|
|
|
|
|
from documents.tasks import index_reindex
|
2020-10-25 23:03:02 +01:00
|
|
|
|
|
|
|
|
|
2021-02-04 23:40:53 +01:00
|
|
|
class Command(BaseCommand):
|
2020-10-25 23:03:02 +01:00
|
|
|
|
2020-10-27 17:08:18 +01:00
|
|
|
help = "Manages the document index."
|
2020-10-25 23:03:02 +01:00
|
|
|
|
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"])
|
2021-04-18 15:56:00 +02:00
|
|
|
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",
|
2021-04-18 15:56:00 +02:00
|
|
|
)
|
2020-10-27 17:08:18 +01:00
|
|
|
|
2020-10-25 23:03:02 +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()
|