This commit is contained in:
+8
-5
@@ -199,10 +199,13 @@ async def get_tv_series_list(dependencies: dict,
|
||||
|
||||
where_clause = " AND ".join(where_conditions) if where_conditions else "1=1"
|
||||
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
|
||||
if having_clause:
|
||||
# When using HAVING clause, need to count filtered results
|
||||
if having_clause or needs_episode_join:
|
||||
# When using HAVING clause or filtering by episode fields, need to count filtered results with JOIN
|
||||
count_query = f"""
|
||||
SELECT COUNT(*) FROM (
|
||||
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
|
||||
WHERE {where_clause}
|
||||
GROUP BY s.imdb_id
|
||||
HAVING {having_clause}
|
||||
{('HAVING ' + having_clause) if having_clause else ''}
|
||||
) filtered_series
|
||||
"""
|
||||
cursor.execute(count_query, params)
|
||||
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}"
|
||||
cursor.execute(count_query, params)
|
||||
total_count = db._get_first_value(cursor.fetchone())
|
||||
|
||||
Reference in New Issue
Block a user