From 0377810bd803db48af77e6efeea256411fe3ca2b Mon Sep 17 00:00:00 2001 From: Matt Duran Date: Fri, 17 Oct 2025 20:37:42 -0700 Subject: [PATCH] fix: Ensure collection cache uses correct value on config change When configuration is saved, Jellyfin creates a new configuration object, so we need to pass the new collection title directly to the refresh method instead of reading from the Configuration property which may still hold the old value during the setter execution. Changes: - Pass collectionTitle parameter to RefreshTubeArchivistCollectionId() - Update CacheTubeArchivistCollectionId() to accept optional title parameter - Prevents searching for stale collection name when config changes --- .../Configuration/PluginConfiguration.cs | 20 ++++++------------- .../Plugin.cs | 19 +++++++++--------- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/Jellyfin.Plugin.TubeArchivistMetadata/Configuration/PluginConfiguration.cs b/Jellyfin.Plugin.TubeArchivistMetadata/Configuration/PluginConfiguration.cs index cd460b0..f133b36 100644 --- a/Jellyfin.Plugin.TubeArchivistMetadata/Configuration/PluginConfiguration.cs +++ b/Jellyfin.Plugin.TubeArchivistMetadata/Configuration/PluginConfiguration.cs @@ -56,22 +56,14 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.Configuration set { - // Only refresh if value actually changed AND plugin is initialized - if (_collectionTitle != value && !string.IsNullOrEmpty(_collectionTitle)) - { - _collectionTitle = value; - _logger?.LogInformation("Collection title changed to: {CollectionTitle}", value); + _collectionTitle = value; - // Only refresh if plugin is fully initialized - if (Plugin.Instance?.LibraryManager != null) - { - Plugin.Instance?.RefreshTubeArchivistCollectionId(); - } - } - else + // Refresh cache if plugin is initialized and value is not empty + if (!string.IsNullOrEmpty(value) && Plugin.Instance?.LibraryManager != null) { - // Initial set, no refresh needed - _collectionTitle = value; + _logger?.LogInformation("Collection title set to: {CollectionTitle}, refreshing cache", value); + // Pass the new value directly instead of reading from Configuration + Plugin.Instance?.RefreshTubeArchivistCollectionId(value); } } } diff --git a/Jellyfin.Plugin.TubeArchivistMetadata/Plugin.cs b/Jellyfin.Plugin.TubeArchivistMetadata/Plugin.cs index b175959..10acb64 100644 --- a/Jellyfin.Plugin.TubeArchivistMetadata/Plugin.cs +++ b/Jellyfin.Plugin.TubeArchivistMetadata/Plugin.cs @@ -175,15 +175,13 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata TaskScheduler.Default); } - /// - /// Caches the TubeArchivist collection ID for efficient lookups. - /// This is called once during initialization to avoid repeated searches. - /// - private void CacheTubeArchivistCollectionId() + private void CacheTubeArchivistCollectionId(string? collectionTitle = null) { try { - if (string.IsNullOrEmpty(Configuration.CollectionTitle)) + string titleToSearch = collectionTitle ?? Configuration.CollectionTitle; + + if (string.IsNullOrEmpty(titleToSearch)) { Logger.LogWarning("TubeArchivist collection title not configured"); _tubeArchivistCollectionId = null; @@ -198,7 +196,7 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata }); var tubeArchivistCollection = collections.FirstOrDefault(c => - c.Name.Equals(Configuration.CollectionTitle, StringComparison.OrdinalIgnoreCase)); + c.Name.Equals(titleToSearch, StringComparison.OrdinalIgnoreCase)); if (tubeArchivistCollection != null) { @@ -207,7 +205,7 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata } else { - Logger.LogWarning("Could not find TubeArchivist collection with name: {CollectionName}", Configuration.CollectionTitle); + Logger.LogWarning("Could not find TubeArchivist collection with name: {CollectionName}", titleToSearch); _tubeArchivistCollectionId = null; } } @@ -222,10 +220,11 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata /// Refreshes the cached TubeArchivist collection ID. /// Called when the collection title changes in configuration. /// - public void RefreshTubeArchivistCollectionId() + /// Optional collection title to use. If null, reads from Configuration. + public void RefreshTubeArchivistCollectionId(string? collectionTitle = null) { Logger.LogInformation("Refreshing TubeArchivist collection cache due to configuration change"); - CacheTubeArchivistCollectionId(); + CacheTubeArchivistCollectionId(collectionTitle ?? Configuration.CollectionTitle); } ///