mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-06-07 22:29:45 +00:00
Enhancement: document_index reindex --if-needed; simplify Docker startup
Add --if-needed flag to `document_index reindex`: checks _needs_rebuild() (schema version + language sentinels) and skips if index is up to date. Safe to run on every upgrade or startup. Simplify Docker init-search-index script to unconditionally call `reindex --if-needed` — schema/language change detection is now fully delegated to Python. Removes the bash index_version and language file tracking entirely; Tantivy's own sentinels are the source of truth. Update docs: bare metal upgrade step uses --if-needed; Docker note updated to describe the new always-runs-but-skips-if-current behaviour. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -21,10 +21,26 @@ class Command(PaperlessCommand):
|
||||
default=False,
|
||||
help="Wipe and recreate the index from scratch (only used with reindex).",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--if-needed",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help=(
|
||||
"Skip reindex if the index is already up to date. "
|
||||
"Checks schema version and search language sentinels. "
|
||||
"Safe to run on every startup or upgrade."
|
||||
),
|
||||
)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
with transaction.atomic():
|
||||
if options["command"] == "reindex":
|
||||
if options.get("if_needed"):
|
||||
from documents.search._schema import _needs_rebuild
|
||||
|
||||
if not _needs_rebuild(settings.INDEX_DIR):
|
||||
self.stdout.write("Search index is up to date.")
|
||||
return
|
||||
if options.get("recreate"):
|
||||
from documents.search import wipe_index
|
||||
|
||||
|
||||
Reference in New Issue
Block a user