From f903606d3ae3b6214eba37401fe30807925b0043 Mon Sep 17 00:00:00 2001 From: sbcrumb Date: Tue, 14 Oct 2025 16:29:27 -0400 Subject: [PATCH] fix: fix webinterface broken when manual scan --- VERSION | 2 +- api/routes.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/VERSION b/VERSION index eca07e4..7d2ed7c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.1.2 +2.1.4 diff --git a/api/routes.py b/api/routes.py index d5b3692..81870f6 100644 --- a/api/routes.py +++ b/api/routes.py @@ -4,6 +4,7 @@ FastAPI routes for NFOGuard - extracted from main nfoguard.py for modular archit import os import json import requests +import asyncio from pathlib import Path from datetime import datetime, timezone from fastapi import HTTPException, BackgroundTasks, Request @@ -584,15 +585,22 @@ async def manual_scan(background_tasks: BackgroundTasks, path: Optional[str] = N else: # Full series processing - scan subdirectories import re + tv_count = 0 for item in scan_path.iterdir(): if (item.is_dir() and not item.name.lower().startswith('season') and not re.match(r'^season\s+\d+$', item.name, re.IGNORECASE) and nfo_manager.parse_imdb_from_path(item)): + tv_count += 1 try: tv_processor.process_series(item) except Exception as e: print(f"ERROR: Failed processing TV series {item}: {e}") + + # Yield control every 5 TV series to allow other requests + if tv_count % 5 == 0: + await asyncio.sleep(0.1) # 100ms yield to process other requests + print(f"INFO: Processed {tv_count} TV series, yielding to other requests...") if scan_type in ["both", "movies"] and scan_path in config.movie_paths: print(f"INFO: Scanning movies in: {scan_path}") @@ -605,6 +613,12 @@ async def manual_scan(background_tasks: BackgroundTasks, path: Optional[str] = N movie_processor.process_movie(item) except Exception as e: print(f"ERROR: Failed processing movie {item}: {e}") + + # Yield control every 10 movies to allow other requests (webhooks, web interface) + if movie_count % 10 == 0: + await asyncio.sleep(0.1) # 100ms yield to process other requests + print(f"INFO: Processed {movie_count} movies, yielding to other requests...") + print(f"INFO: Completed movie scan: {movie_count} movies processed in {scan_path}") background_tasks.add_task(run_scan)