feat: Add three-tier optimization for maximum performance
Local Docker Build (Dev) / build-dev (push) Successful in 19s
Local Docker Build (Dev) / build-dev (push) Successful in 19s
Implemented smart caching system that dramatically reduces processing time: TIER 1 (Fastest): NFO File Check - If NFO already has NFOGuard dateadded + lockdata, use it directly - Skips both database queries AND API calls - Perfect for movies already processed by NFOGuard TIER 2 (Fast): Database Check - If database has complete dateadded data, use it - Skips expensive API calls to TMDB/OMDB/Radarr - Creates NFO from cached data TIER 3 (Slowest): Full Processing - Only when neither NFO nor database have data - Queries all APIs, processes dates, saves to database This should dramatically improve full scan performance, especially on subsequent runs where most movies already have NFOGuard data. Expected speedup: 90%+ reduction in processing time for warm scans.
This commit is contained in:
@@ -114,6 +114,41 @@ class NFOManager:
|
|||||||
print(f"❌ No IMDb ID found in directory, filenames, or NFO for: {movie_dir.name}")
|
print(f"❌ No IMDb ID found in directory, filenames, or NFO for: {movie_dir.name}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def extract_nfoguard_dates_from_nfo(self, nfo_path: Path) -> Optional[Dict[str, str]]:
|
||||||
|
"""Extract NFOGuard-managed dates from existing NFO file"""
|
||||||
|
if not nfo_path.exists():
|
||||||
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
|
tree = ET.parse(nfo_path)
|
||||||
|
root = tree.getroot()
|
||||||
|
|
||||||
|
# Look for NFOGuard fields
|
||||||
|
dateadded_elem = root.find('.//dateadded')
|
||||||
|
premiered_elem = root.find('.//premiered')
|
||||||
|
lockdata_elem = root.find('.//lockdata')
|
||||||
|
|
||||||
|
# Only consider it NFOGuard-managed if it has dateadded and lockdata
|
||||||
|
if (dateadded_elem is not None and dateadded_elem.text and
|
||||||
|
lockdata_elem is not None and lockdata_elem.text == "true"):
|
||||||
|
|
||||||
|
result = {
|
||||||
|
"dateadded": dateadded_elem.text.strip(),
|
||||||
|
"source": "nfo_file_existing"
|
||||||
|
}
|
||||||
|
|
||||||
|
if premiered_elem is not None and premiered_elem.text:
|
||||||
|
result["released"] = premiered_elem.text.strip()
|
||||||
|
|
||||||
|
print(f"✅ Found NFOGuard data in NFO: dateadded={result['dateadded']}, released={result.get('released', 'None')}")
|
||||||
|
return result
|
||||||
|
|
||||||
|
except (ET.ParseError, Exception) as e:
|
||||||
|
print(f"⚠️ Error parsing NFO for NFOGuard data: {e}")
|
||||||
|
pass
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
def _parse_nfo_with_tolerance(self, nfo_path: Path):
|
def _parse_nfo_with_tolerance(self, nfo_path: Path):
|
||||||
"""Parse NFO file with tolerance for URLs appended after XML"""
|
"""Parse NFO file with tolerance for URLs appended after XML"""
|
||||||
try:
|
try:
|
||||||
|
|||||||
+17
-1
@@ -970,7 +970,23 @@ class MovieProcessor:
|
|||||||
self.db.upsert_movie_dates(imdb_id, None, None, None, False)
|
self.db.upsert_movie_dates(imdb_id, None, None, None, False)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Get existing dates
|
# TIER 1: Check if NFO file already has NFOGuard data (fastest - no DB or API calls)
|
||||||
|
nfo_path = movie_path / "movie.nfo"
|
||||||
|
nfo_data = self.nfo_manager.extract_nfoguard_dates_from_nfo(nfo_path)
|
||||||
|
if nfo_data:
|
||||||
|
_log("INFO", f"🚀 Using existing NFOGuard data from NFO file: {nfo_data['dateadded']} (source: {nfo_data['source']})")
|
||||||
|
dateadded = nfo_data["dateadded"]
|
||||||
|
source = nfo_data["source"]
|
||||||
|
released = nfo_data.get("released")
|
||||||
|
|
||||||
|
# Update file mtimes if enabled (NFO is already correct)
|
||||||
|
if config.fix_dir_mtimes and dateadded:
|
||||||
|
self.nfo_manager.update_movie_files_mtime(movie_path, dateadded)
|
||||||
|
|
||||||
|
_log("INFO", f"Completed processing movie: {movie_path.name} (source: {source}) [nfo-only]")
|
||||||
|
return
|
||||||
|
|
||||||
|
# TIER 2: Check database for existing data
|
||||||
existing = self.db.get_movie_dates(imdb_id)
|
existing = self.db.get_movie_dates(imdb_id)
|
||||||
_log("DEBUG", f"Database lookup for {imdb_id}: {existing}")
|
_log("DEBUG", f"Database lookup for {imdb_id}: {existing}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user