From 6f04031e332313964efc821e94e20e227519eb83 Mon Sep 17 00:00:00 2001 From: SBCrumb Date: Tue, 9 Sep 2025 18:02:33 -0400 Subject: [PATCH] Add debug logging to diagnose Matrix history issue - Show first 3 events in movie history - Log event types to identify if first event is rename (Type 7) - Debug why Matrix (tt0133093) not detecting rename-first pattern --- clients/radarr_db_client.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/clients/radarr_db_client.py b/clients/radarr_db_client.py index 8cd7f47..42dfce1 100644 --- a/clients/radarr_db_client.py +++ b/clients/radarr_db_client.py @@ -266,11 +266,11 @@ class RadarrDbClient: In such cases, we should prefer release dates over the upgrade date """ query = """ - SELECT h."EventType" as event_type + SELECT h."EventType" as event_type, h."Date" as event_date FROM "History" h WHERE h."MovieId" = %s ORDER BY h."Date" ASC - LIMIT 1 + LIMIT 3 """ if self.db_type == "sqlite": @@ -284,15 +284,25 @@ class RadarrDbClient: cursor = conn.cursor() cursor.execute(query, (movie_id,)) - row = cursor.fetchone() + rows = cursor.fetchall() - if row: - event_type = row['event_type'] if self.db_type == "postgresql" else row[0] - # EventType 7 = movieFileRenamed - return event_type == 7 + if rows: + _log("INFO", f"Movie {movie_id} history debug - first 3 events:") + for i, row in enumerate(rows): + event_type = row['event_type'] if self.db_type == "postgresql" else row[0] + event_date = row['event_date'] if self.db_type == "postgresql" else row[1] + _log("INFO", f" Event {i+1}: Type={event_type}, Date={event_date}") + + first_event_type = rows[0]['event_type'] if self.db_type == "postgresql" else rows[0][0] + # EventType 7 = movieFileRenamed + is_rename_first = first_event_type == 7 + _log("INFO", f"Movie {movie_id}: First event type={first_event_type}, is_rename_first={is_rename_first}") + return is_rename_first + else: + _log("INFO", f"Movie {movie_id}: No history events found") except Exception as e: - _log("DEBUG", f"Error checking first event type for movie {movie_id}: {e}") + _log("ERROR", f"Error checking first event type for movie {movie_id}: {e}") return False