feat(deep-scan): trigger accepts 'deep'; scan_directory(mode) + enqueue backfill_phash

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-19 15:09:19 -04:00
parent ae67e67299
commit 9535533385
3 changed files with 45 additions and 7 deletions
+12 -3
View File
@@ -34,8 +34,12 @@ def _sync_session_factory():
@celery.task(name="backend.app.tasks.scan.scan_directory", bind=True)
def scan_directory(self, triggered_by: str = "manual") -> int:
"""Walks the import root and creates ImportTasks. Returns the batch id."""
def scan_directory(self, triggered_by: str = "manual",
mode: str = "quick") -> int:
"""Walks the import root and creates ImportTasks. `mode` is 'quick'
or 'deep'; deep also enqueues a library-wide phash backfill and (via
Importer.deep) re-derives on already-imported files. Returns the
batch id."""
SessionLocal = _sync_session_factory()
with SessionLocal() as session:
settings = session.execute(
@@ -46,7 +50,7 @@ def scan_directory(self, triggered_by: str = "manual") -> int:
batch = ImportBatch(
triggered_by=triggered_by,
source_path=str(import_root),
scan_mode="quick", # FC-2a is quick only; FC-2d adds 'deep'
scan_mode=mode,
status="running",
)
session.add(batch)
@@ -84,4 +88,9 @@ def scan_directory(self, triggered_by: str = "manual") -> int:
import_media_file.delay(task.id)
session.commit()
if mode == "deep":
from .maintenance import backfill_phash
backfill_phash.delay()
return batch_id