fix(scan): auto-finalize empty scans + system_stats picks running batch with actual work

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-23 21:25:57 -04:00
parent 38a45baad5
commit 7a5a71471e
2 changed files with 23 additions and 2 deletions
+9
View File
@@ -95,6 +95,15 @@ def scan_directory(self, triggered_by: str = "manual",
files_seen += 1
batch.total_files = files_seen
# If the walk enqueued nothing (every file was already on a
# non-failed ImportTask from a prior scan), there's no
# import_media_file message that would ever flip this batch to
# 'complete' — finalize it now so the active-batch query in
# /api/system/stats doesn't get stuck reporting all-zero
# counters from an empty scan.
if files_seen == 0:
batch.status = "complete"
batch.finished_at = datetime.now(UTC)
session.commit()
# Now enqueue import_media_file for each pending task.