Remove dependency on OptimizedPriorityQueue

This commit is contained in:
Bond_009 2022-12-07 18:02:12 +01:00
parent 3cb7fe5012
commit 9bb1bc5a3e
4 changed files with 18 additions and 27 deletions

View File

@ -1154,7 +1154,7 @@ namespace Emby.Server.Implementations.Library
.ToList();
}
private VirtualFolderInfo GetVirtualFolderInfo(string dir, List<BaseItem> allCollectionFolders, Dictionary<Guid, Guid> refreshQueue)
private VirtualFolderInfo GetVirtualFolderInfo(string dir, List<BaseItem> allCollectionFolders, HashSet<Guid> refreshQueue)
{
var info = new VirtualFolderInfo
{
@ -1182,22 +1182,22 @@ namespace Emby.Server.Implementations.Library
};
var libraryFolder = allCollectionFolders.FirstOrDefault(i => string.Equals(i.Path, dir, StringComparison.OrdinalIgnoreCase));
if (libraryFolder is not null && libraryFolder.HasImage(ImageType.Primary))
{
info.PrimaryImageItemId = libraryFolder.Id.ToString("N", CultureInfo.InvariantCulture);
}
if (libraryFolder is not null)
{
info.ItemId = libraryFolder.Id.ToString("N", CultureInfo.InvariantCulture);
var libraryFolderId = libraryFolder.Id.ToString("N", CultureInfo.InvariantCulture);
info.ItemId = libraryFolderId;
if (libraryFolder.HasImage(ImageType.Primary))
{
info.PrimaryImageItemId = libraryFolderId;
}
info.LibraryOptions = GetLibraryOptions(libraryFolder);
if (refreshQueue is not null)
{
info.RefreshProgress = libraryFolder.GetRefreshProgress();
info.RefreshStatus = info.RefreshProgress.HasValue ? "Active" : refreshQueue.ContainsKey(libraryFolder.Id) ? "Queued" : "Idle";
info.RefreshStatus = info.RefreshProgress.HasValue ? "Active" : refreshQueue.Contains(libraryFolder.Id) ? "Queued" : "Idle";
}
}

View File

@ -216,7 +216,7 @@ namespace MediaBrowser.Controller.Providers
/// <returns>Task{HttpResponseInfo}.</returns>
Task<HttpResponseMessage> GetSearchImage(string providerName, string url, CancellationToken cancellationToken);
Dictionary<Guid, Guid> GetRefreshQueue();
HashSet<Guid> GetRefreshQueue();
void OnRefreshStart(BaseItem item);

View File

@ -31,7 +31,6 @@ using MediaBrowser.Model.IO;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.Providers;
using Microsoft.Extensions.Logging;
using Priority_Queue;
using Book = MediaBrowser.Controller.Entities.Book;
using Episode = MediaBrowser.Controller.Entities.TV.Episode;
using Movie = MediaBrowser.Controller.Entities.Movies.Movie;
@ -58,7 +57,7 @@ namespace MediaBrowser.Providers.Manager
private readonly IBaseItemManager _baseItemManager;
private readonly ConcurrentDictionary<Guid, double> _activeRefreshes = new();
private readonly CancellationTokenSource _disposeCancellationTokenSource = new();
private readonly SimplePriorityQueue<Tuple<Guid, MetadataRefreshOptions>> _refreshQueue = new();
private readonly PriorityQueue<(Guid ItemId, MetadataRefreshOptions RefreshOptions), RefreshPriority> _refreshQueue = new();
private IImageProvider[] _imageProviders = Array.Empty<IImageProvider>();
private IMetadataService[] _metadataServices = Array.Empty<IMetadataService>();
@ -897,18 +896,11 @@ namespace MediaBrowser.Providers.Manager
}
/// <inheritdoc/>
public Dictionary<Guid, Guid> GetRefreshQueue()
public HashSet<Guid> GetRefreshQueue()
{
lock (_refreshQueueLock)
{
var dict = new Dictionary<Guid, Guid>();
foreach (var item in _refreshQueue)
{
dict[item.Item1] = item.Item1;
}
return dict;
return _refreshQueue.UnorderedItems.Select(x => x.Element.ItemId).ToHashSet();
}
}
@ -969,7 +961,7 @@ namespace MediaBrowser.Providers.Manager
return;
}
_refreshQueue.Enqueue(new Tuple<Guid, MetadataRefreshOptions>(itemId, options), (int)priority);
_refreshQueue.Enqueue((itemId, options), priority);
lock (_refreshQueueLock)
{
@ -992,7 +984,7 @@ namespace MediaBrowser.Providers.Manager
var cancellationToken = _disposeCancellationTokenSource.Token;
while (_refreshQueue.TryDequeue(out Tuple<Guid, MetadataRefreshOptions> refreshItem))
while (_refreshQueue.TryDequeue(out var refreshItem, out _))
{
if (_disposed)
{
@ -1001,15 +993,15 @@ namespace MediaBrowser.Providers.Manager
try
{
var item = libraryManager.GetItemById(refreshItem.Item1);
var item = libraryManager.GetItemById(refreshItem.ItemId);
if (item is null)
{
continue;
}
var task = item is MusicArtist artist
? RefreshArtist(artist, refreshItem.Item2, cancellationToken)
: RefreshItem(item, refreshItem.Item2, cancellationToken);
? RefreshArtist(artist, refreshItem.RefreshOptions, cancellationToken)
: RefreshItem(item, refreshItem.RefreshOptions, cancellationToken);
await task.ConfigureAwait(false);
}

View File

@ -22,7 +22,6 @@
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="OptimizedPriorityQueue" Version="5.1.0" />
<PackageReference Include="PlaylistsNET" Version="1.2.1" />
<PackageReference Include="TagLibSharp" Version="2.3.0" />
<PackageReference Include="TMDbLib" Version="1.9.2" />