Skip to content
24 changes: 23 additions & 1 deletion app/services/scan_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,20 @@ def _run_scan_job(self, job_data):
if library:
self.logger.info(f"Starting SCAN job {job_id}")
scanner = LibraryScanner(library, db_scan)
results = scanner.scan(force=force)

use_parallel = get_cached_setting("system.parallel_metadata_processing", False)

self.logger.info(f"Parallel metadata processing is set to {use_parallel}")

# UNIFIED LOGIC:
# If Parallel is ON: Let the service auto-detect worker count (0)
# If Parallel is OFF: Force exactly 1 worker
workers = 0 if use_parallel else 1

results = scanner.scan_parallel(force=force, worker_limit=workers)

ScanManager.update_library_last_scanned(library_id)

else:
error = "Library not found"
except Exception as e:
Expand Down Expand Up @@ -436,6 +449,15 @@ def add_thumbnail_task(self, library_id: int, force: bool = False) -> dict:
finally:
db.close()

@staticmethod
def update_library_last_scanned(library_id: int):
db = SessionLocal()
lib = db.query(Library).get(library_id)
if lib:
lib.last_scanned = datetime.utcnow()
db.commit()
db.close()



# Global instance
Expand Down
Loading