mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-07-09 23:30:50 +02:00
Merge pull request #10276 from Bond-009/concurrentdict
CollectionFolder: replace Dictionary + locks with ConcurrentDictionary
This commit is contained in:
commit
2ae2145192
|
@ -3,6 +3,7 @@
|
||||||
#pragma warning disable CS1591
|
#pragma warning disable CS1591
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
@ -29,7 +30,7 @@ namespace MediaBrowser.Controller.Entities
|
||||||
public class CollectionFolder : Folder, ICollectionFolder
|
public class CollectionFolder : Folder, ICollectionFolder
|
||||||
{
|
{
|
||||||
private static readonly JsonSerializerOptions _jsonOptions = JsonDefaults.Options;
|
private static readonly JsonSerializerOptions _jsonOptions = JsonDefaults.Options;
|
||||||
private static readonly Dictionary<string, LibraryOptions> _libraryOptions = new Dictionary<string, LibraryOptions>();
|
private static readonly ConcurrentDictionary<string, LibraryOptions> _libraryOptions = new ConcurrentDictionary<string, LibraryOptions>();
|
||||||
private bool _requiresRefresh;
|
private bool _requiresRefresh;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -139,45 +140,26 @@ namespace MediaBrowser.Controller.Entities
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LibraryOptions GetLibraryOptions(string path)
|
public static LibraryOptions GetLibraryOptions(string path)
|
||||||
{
|
=> _libraryOptions.GetOrAdd(path, LoadLibraryOptions);
|
||||||
lock (_libraryOptions)
|
|
||||||
{
|
|
||||||
if (!_libraryOptions.TryGetValue(path, out var options))
|
|
||||||
{
|
|
||||||
options = LoadLibraryOptions(path);
|
|
||||||
_libraryOptions[path] = options;
|
|
||||||
}
|
|
||||||
|
|
||||||
return options;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void SaveLibraryOptions(string path, LibraryOptions options)
|
public static void SaveLibraryOptions(string path, LibraryOptions options)
|
||||||
{
|
{
|
||||||
lock (_libraryOptions)
|
_libraryOptions[path] = options;
|
||||||
|
|
||||||
|
var clone = JsonSerializer.Deserialize<LibraryOptions>(JsonSerializer.SerializeToUtf8Bytes(options, _jsonOptions), _jsonOptions);
|
||||||
|
foreach (var mediaPath in clone.PathInfos)
|
||||||
{
|
{
|
||||||
_libraryOptions[path] = options;
|
if (!string.IsNullOrEmpty(mediaPath.Path))
|
||||||
|
|
||||||
var clone = JsonSerializer.Deserialize<LibraryOptions>(JsonSerializer.SerializeToUtf8Bytes(options, _jsonOptions), _jsonOptions);
|
|
||||||
foreach (var mediaPath in clone.PathInfos)
|
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(mediaPath.Path))
|
mediaPath.Path = ApplicationHost.ReverseVirtualPath(mediaPath.Path);
|
||||||
{
|
|
||||||
mediaPath.Path = ApplicationHost.ReverseVirtualPath(mediaPath.Path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlSerializer.SerializeToFile(clone, GetLibraryOptionsPath(path));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
XmlSerializer.SerializeToFile(clone, GetLibraryOptionsPath(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void OnCollectionFolderChange()
|
public static void OnCollectionFolderChange()
|
||||||
{
|
=> _libraryOptions.Clear();
|
||||||
lock (_libraryOptions)
|
|
||||||
{
|
|
||||||
_libraryOptions.Clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool IsSaveLocalMetadataEnabled()
|
public override bool IsSaveLocalMetadataEnabled()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue