Implement initial NFO scan tracking for one-time setup
- Add NFO scanning to startup process (fastapi_app.py) - Check initial_nfo_scan_completed flag before running NFO scan - Run NFO scan only on first startup if TMDB API key is configured - Mark NFO scan as completed after first successful run - Skip NFO scan on subsequent startups This ensures NFO metadata processing only occurs during initial setup, not on every application restart, improving startup performance.
This commit is contained in:
@@ -124,10 +124,10 @@ make sure you maintain the function on one location
|
||||
|
||||
1. ✅ scanning anime from folder - COMPLETED
|
||||
Implemented initial scan tracking using SystemSettings table. Anime folder scanning now only runs during initial setup, not on each application start.
|
||||
- Added SystemSettings model with initial_scan_completed flag
|
||||
- Created SystemSettingsService for managing setup state
|
||||
- Modified fastapi_app.py to check scan completion status on startup
|
||||
- Added unit test for SystemSettingsService
|
||||
- Added SystemSettings model with initial_scan_completed flag
|
||||
- Created SystemSettingsService for managing setup state
|
||||
- Modified fastapi_app.py to check scan completion status on startup
|
||||
- Added unit test for SystemSettingsService
|
||||
|
||||
2. Nfo scan
|
||||
make sure nfo scan runs only on setup and not on each start
|
||||
|
||||
@@ -256,6 +256,70 @@ async def lifespan(_application: FastAPI):
|
||||
await anime_service._load_series_from_db()
|
||||
logger.info("Series loaded from database into memory")
|
||||
|
||||
# Check if initial NFO scan has been completed
|
||||
try:
|
||||
async with get_db_session() as db:
|
||||
is_nfo_scan_done = (
|
||||
await SystemSettingsService
|
||||
.is_initial_nfo_scan_completed(db)
|
||||
)
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
"Failed to check NFO scan status: %s, assuming not done",
|
||||
e
|
||||
)
|
||||
is_nfo_scan_done = False
|
||||
|
||||
# Run NFO scan only on first run (if configured)
|
||||
if settings.tmdb_api_key and (
|
||||
settings.nfo_auto_create or settings.nfo_update_on_scan
|
||||
):
|
||||
if not is_nfo_scan_done:
|
||||
logger.info("Performing initial NFO scan...")
|
||||
try:
|
||||
from src.core.services.series_manager_service import (
|
||||
SeriesManagerService,
|
||||
)
|
||||
|
||||
manager = SeriesManagerService.from_settings()
|
||||
await manager.scan_and_process_nfo()
|
||||
await manager.close()
|
||||
logger.info("Initial NFO scan completed")
|
||||
|
||||
# Mark NFO scan as completed
|
||||
try:
|
||||
async with get_db_session() as db:
|
||||
await (
|
||||
SystemSettingsService
|
||||
.mark_initial_nfo_scan_completed(db)
|
||||
)
|
||||
logger.info("Marked NFO scan as completed")
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
"Failed to mark NFO scan as completed: %s",
|
||||
e
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
"Failed to complete NFO scan: %s",
|
||||
e,
|
||||
exc_info=True
|
||||
)
|
||||
else:
|
||||
logger.info(
|
||||
"Skipping NFO scan - already completed on previous run"
|
||||
)
|
||||
else:
|
||||
if not settings.tmdb_api_key:
|
||||
logger.info(
|
||||
"NFO scan skipped - TMDB API key not configured"
|
||||
)
|
||||
else:
|
||||
logger.info(
|
||||
"NFO scan skipped - auto_create and update_on_scan "
|
||||
"both disabled"
|
||||
)
|
||||
|
||||
# Now initialize download service (will use data from database)
|
||||
from src.server.utils.dependencies import get_download_service
|
||||
download_service = get_download_service()
|
||||
|
||||
Reference in New Issue
Block a user