diff --git a/server/routes/webhook.js b/server/routes/webhook.js index 9bf5797..483c27c 100644 --- a/server/routes/webhook.js +++ b/server/routes/webhook.js @@ -247,10 +247,14 @@ router.post('/sonarr', webhookLimiter, (req, res) => { logToFile(`[Webhook] Sonarr payload: ${JSON.stringify(req.body)}`); // Phase 5.1: update webhook metrics for polling optimization + // Note: instanceName from webhook is often generic (e.g., "Sonarr"), not the configured name + // Update metrics for all Sonarr instances since we can't reliably match const sonarrInstances = getSonarrInstances(); - const instance = sonarrInstances.find(i => i.name === instanceName); - if (instance) { - cache.updateWebhookMetrics(instance.url); + if (sonarrInstances.length > 0) { + for (const inst of sonarrInstances) { + cache.updateWebhookMetrics(inst.url); + } + logToFile(`[Webhook] Updated metrics for ${sonarrInstances.length} Sonarr instance(s)`); } // Phase 2: background cache refresh + SSE broadcast (fire-and-forget) @@ -296,10 +300,14 @@ router.post('/radarr', webhookLimiter, (req, res) => { logToFile(`[Webhook] Radarr payload: ${JSON.stringify(req.body)}`); // Phase 5.1: update webhook metrics for polling optimization + // Note: instanceName from webhook is often generic (e.g., "Radarr"), not the configured name + // Update metrics for all Radarr instances since we can't reliably match const radarrInstances = getRadarrInstances(); - const instance = radarrInstances.find(i => i.name === instanceName); - if (instance) { - cache.updateWebhookMetrics(instance.url); + if (radarrInstances.length > 0) { + for (const inst of radarrInstances) { + cache.updateWebhookMetrics(inst.url); + } + logToFile(`[Webhook] Updated metrics for ${radarrInstances.length} Radarr instance(s)`); } // Phase 2: background cache refresh + SSE broadcast (fire-and-forget) diff --git a/server/utils/downloadClients.js b/server/utils/downloadClients.js index 60ea6ed..50a7785 100644 --- a/server/utils/downloadClients.js +++ b/server/utils/downloadClients.js @@ -63,8 +63,9 @@ class DownloadClientRegistry { } const client = new ClientClass(config); - this.clients.set(config.id, client); - logToFile(`[DownloadClientRegistry] Created ${config.type} client: ${config.name} (${config.id})`); + const uniqueKey = `${config.type}:${config.id}`; + this.clients.set(uniqueKey, client); + logToFile(`[DownloadClientRegistry] Created ${config.type} client: ${config.name} (${uniqueKey})`); } catch (error) { logToFile(`[DownloadClientRegistry] Failed to create client ${config.id}: ${error.message}`); }