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
This commit is contained in:
Matt Duran 2025-10-17 20:37:42 -07:00
parent c0bafbb1da
commit 0377810bd8
2 changed files with 15 additions and 24 deletions

View File

@ -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);
}
}
}

View File

@ -175,15 +175,13 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata
TaskScheduler.Default);
}
/// <summary>
/// Caches the TubeArchivist collection ID for efficient lookups.
/// This is called once during initialization to avoid repeated searches.
/// </summary>
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.
/// </summary>
public void RefreshTubeArchivistCollectionId()
/// <param name="collectionTitle">Optional collection title to use. If null, reads from Configuration.</param>
public void RefreshTubeArchivistCollectionId(string? collectionTitle = null)
{
Logger.LogInformation("Refreshing TubeArchivist collection cache due to configuration change");
CacheTubeArchivistCollectionId();
CacheTubeArchivistCollectionId(collectionTitle ?? Configuration.CollectionTitle);
}
/// <summary>