fix: movie fixes
Local Docker Build (Dev) / build-dev (push) Successful in 5s

This commit is contained in:
2025-11-03 14:07:00 -05:00
parent e397f0639b
commit 73967da3e6
6 changed files with 66 additions and 13 deletions
+1 -1
View File
@@ -1 +1 @@
2.8.4-populate-fix4 2.8.6-sql-fix
+7 -4
View File
@@ -200,9 +200,12 @@ async def get_tv_series_list(dependencies: dict,
where_clause = " AND ".join(where_conditions) if where_conditions else "1=1" where_clause = " AND ".join(where_conditions) if where_conditions else "1=1"
having_clause = " AND ".join(having_conditions) if having_conditions else "" having_clause = " AND ".join(having_conditions) if having_conditions else ""
# Check if where_clause references episodes table (e.source, e.dateadded, etc.)
needs_episode_join = any(cond.startswith("e.") for cond in where_conditions)
# Get total count with same filtering logic as main query # Get total count with same filtering logic as main query
if having_clause: if having_clause or needs_episode_join:
# When using HAVING clause, need to count filtered results # When using HAVING clause or filtering by episode fields, need to count filtered results with JOIN
count_query = f""" count_query = f"""
SELECT COUNT(*) FROM ( SELECT COUNT(*) FROM (
SELECT s.imdb_id SELECT s.imdb_id
@@ -210,12 +213,12 @@ async def get_tv_series_list(dependencies: dict,
LEFT JOIN episodes e ON s.imdb_id = e.imdb_id LEFT JOIN episodes e ON s.imdb_id = e.imdb_id
WHERE {where_clause} WHERE {where_clause}
GROUP BY s.imdb_id GROUP BY s.imdb_id
HAVING {having_clause} {('HAVING ' + having_clause) if having_clause else ''}
) filtered_series ) filtered_series
""" """
cursor.execute(count_query, params) cursor.execute(count_query, params)
else: else:
# Simple count when no HAVING clause # Simple count when no HAVING clause and no episode filtering
count_query = f"SELECT COUNT(*) FROM series s WHERE {where_clause}" count_query = f"SELECT COUNT(*) FROM series s WHERE {where_clause}"
cursor.execute(count_query, params) cursor.execute(count_query, params)
total_count = db._get_first_value(cursor.fetchone()) total_count = db._get_first_value(cursor.fetchone())
+45
View File
@@ -165,6 +165,51 @@ class RadarrDbClient:
return None return None
def get_all_movies(self) -> List[Dict[str, Any]]:
"""
Get all movies from Radarr database
Returns:
List of dictionaries with movie info
"""
query = """
SELECT
m."Id" as id,
m."Path" as path,
m."Added" as added,
mm."ImdbId" as imdb_id,
mm."Title" as title,
mm."Year" as year,
mm."DigitalRelease" as digital_release,
mm."PhysicalRelease" as physical_release,
mm."InCinemas" as in_cinemas
FROM "Movies" m
JOIN "MovieMetadata" mm ON m."MovieMetadataId" = mm."Id"
ORDER BY mm."Title"
"""
if self.db_type == "sqlite":
# SQLite uses ? placeholders but this query has none
pass
try:
with self._get_connection() as conn:
if self.db_type == "postgresql":
cursor = conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
else:
cursor = conn.cursor()
cursor.execute(query)
rows = cursor.fetchall()
if rows:
return [dict(row) if self.db_type == "sqlite" else row for row in rows]
return []
except Exception as e:
_log("ERROR", f"Database query error getting all movies: {e}")
return []
def get_earliest_import_date(self, movie_id: int) -> Tuple[Optional[str], str]: def get_earliest_import_date(self, movie_id: int) -> Tuple[Optional[str], str]:
""" """
Get earliest import date from History table, accounting for upgrade scenarios Get earliest import date from History table, accounting for upgrade scenarios
+8 -3
View File
@@ -49,10 +49,15 @@ class DatabasePopulator:
} }
try: try:
# Get all movies from Radarr # Get all movies from Radarr database
movies = self.radarr.get_all_movies() if not hasattr(self.radarr, 'db_client') or not self.radarr.db_client:
_log("ERROR", "Radarr database client not available - cannot populate movies")
stats['errors'] += 1
return stats
movies = self.radarr.db_client.get_all_movies()
if not movies: if not movies:
_log("WARNING", "No movies found in Radarr") _log("WARNING", "No movies found in Radarr database")
return stats return stats
stats['total'] = len(movies) stats['total'] = len(movies)
+1 -1
View File
@@ -33,7 +33,7 @@ def create_web_app() -> FastAPI:
app = FastAPI( app = FastAPI(
title="NFOGuard Web Interface", title="NFOGuard Web Interface",
description="Web interface for NFOGuard media database management", description="Web interface for NFOGuard media database management",
version="2.8.1-populate-fix", version="2.8.6-sql-fix",
docs_url="/docs" if web_config.web_debug else None, docs_url="/docs" if web_config.web_debug else None,
redoc_url="/redoc" if web_config.web_debug else None redoc_url="/redoc" if web_config.web_debug else None
) )
+2 -2
View File
@@ -29,7 +29,7 @@ def create_web_app() -> FastAPI:
app = FastAPI( app = FastAPI(
title="NFOGuard Web Interface", title="NFOGuard Web Interface",
description="Web interface for NFOGuard media database management", description="Web interface for NFOGuard media database management",
version="2.8.3-populate-fix3", version="2.8.6-sql-fix",
docs_url=None, # Disable docs in production docs_url=None, # Disable docs in production
redoc_url=None redoc_url=None
) )
@@ -94,7 +94,7 @@ def setup_static_files(app: FastAPI) -> None:
"status": "healthy", "status": "healthy",
"service": "nfoguard-web", "service": "nfoguard-web",
"timestamp": time.time(), "timestamp": time.time(),
"version": "2.8.3-populate-fix3" "version": "2.8.6-sql-fix"
} }
except Exception as e: except Exception as e:
from fastapi import HTTPException from fastapi import HTTPException