Fix all Sonarr webhooks: Force targeted processing for single episodes
Local Docker Build (Dev) / build-dev (pull_request) Successful in 3s
Local Docker Build (Dev) / build-dev (pull_request) Successful in 3s
- Extend episodeFile extraction to ALL webhook types (Download, Rename, Upgrade) - Force targeted mode when episodes_data has ≤3 episodes to prevent full series processing - Add debug logging to track episode extraction and processing mode decisions - Prevents processing 177 episodes when only 1-3 episodes are involved - Applies to imports, renames, and upgrades - not just renames - Version bump to 2.0.12 This ensures that single episode operations (most common) only process the specific episode(s) involved instead of scanning the entire series.
This commit is contained in:
+12
-4
@@ -74,9 +74,11 @@ async def sonarr_webhook(request: Request, background_tasks: BackgroundTasks, de
|
|||||||
|
|
||||||
# Extract episode data for targeted processing
|
# Extract episode data for targeted processing
|
||||||
episodes_data = webhook.episodes or []
|
episodes_data = webhook.episodes or []
|
||||||
|
print(f"DEBUG: Initial episodes_data from webhook.episodes: {len(episodes_data)} episodes")
|
||||||
|
|
||||||
# For rename events, if no episodes in webhook.episodes, try to extract from episodeFile
|
# For all webhook events, if no episodes in webhook.episodes, try to extract from episodeFile
|
||||||
if webhook.eventType == "Rename" and not episodes_data and webhook.episodeFile:
|
# This ensures targeted processing for single episode operations (Download, Rename, Upgrade)
|
||||||
|
if not episodes_data and webhook.episodeFile:
|
||||||
episode_file = webhook.episodeFile
|
episode_file = webhook.episodeFile
|
||||||
# Extract season and episode from episodeFile if available
|
# Extract season and episode from episodeFile if available
|
||||||
season_num = episode_file.get("seasonNumber")
|
season_num = episode_file.get("seasonNumber")
|
||||||
@@ -89,7 +91,13 @@ async def sonarr_webhook(request: Request, background_tasks: BackgroundTasks, de
|
|||||||
"id": episode_file.get("id"),
|
"id": episode_file.get("id"),
|
||||||
"title": episode_file.get("title")
|
"title": episode_file.get("title")
|
||||||
}]
|
}]
|
||||||
print(f"INFO: Extracted episode info from episodeFile for rename: S{season_num:02d}E{episode_num:02d}")
|
print(f"INFO: Extracted episode info from episodeFile for {webhook.eventType}: S{season_num:02d}E{episode_num:02d}")
|
||||||
|
|
||||||
|
# Force targeted mode for single-episode webhooks to prevent full series processing
|
||||||
|
processing_mode = config.tv_webhook_processing_mode
|
||||||
|
if episodes_data and len(episodes_data) <= 3: # Single episode or small batch
|
||||||
|
processing_mode = "targeted"
|
||||||
|
print(f"INFO: Forcing targeted mode for {len(episodes_data)} episode(s)")
|
||||||
|
|
||||||
# Add to batch queue with TV-prefixed key to avoid movie conflicts
|
# Add to batch queue with TV-prefixed key to avoid movie conflicts
|
||||||
tv_batch_key = f"tv:{imdb_id}"
|
tv_batch_key = f"tv:{imdb_id}"
|
||||||
@@ -98,7 +106,7 @@ async def sonarr_webhook(request: Request, background_tasks: BackgroundTasks, de
|
|||||||
'series_info': series_info,
|
'series_info': series_info,
|
||||||
'event_type': webhook.eventType,
|
'event_type': webhook.eventType,
|
||||||
'episodes': episodes_data, # Include enhanced episode data for targeted processing
|
'episodes': episodes_data, # Include enhanced episode data for targeted processing
|
||||||
'processing_mode': config.tv_webhook_processing_mode
|
'processing_mode': processing_mode # Use forced targeted mode when appropriate
|
||||||
}
|
}
|
||||||
batcher.add_webhook(tv_batch_key, webhook_dict, 'tv')
|
batcher.add_webhook(tv_batch_key, webhook_dict, 'tv')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user