mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-06-02 13:58:29 +01:00
calculate item by name counts on the fly
This commit is contained in:
@@ -484,6 +484,9 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
await ItemRepository.DeleteItem(child.Id, CancellationToken.None).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
BaseItem removed;
|
||||
_libraryItemsCache.TryRemove(item.Id, out removed);
|
||||
|
||||
ReportItemRemoved(item);
|
||||
}
|
||||
|
||||
@@ -922,10 +925,10 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
/// <returns>Task.</returns>
|
||||
public Task ValidatePeople(CancellationToken cancellationToken, IProgress<double> progress)
|
||||
{
|
||||
// Ensure the location is unavailable.
|
||||
// Ensure the location is available.
|
||||
Directory.CreateDirectory(ConfigurationManager.ApplicationPaths.PeoplePath);
|
||||
|
||||
return new PeopleValidator(this, _logger).ValidatePeople(cancellationToken, progress);
|
||||
return new PeopleValidator(this, _logger).ValidatePeople(cancellationToken, new MetadataRefreshOptions(), progress);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -953,7 +956,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
// Ensure the location is unavailable.
|
||||
Directory.CreateDirectory(ConfigurationManager.ApplicationPaths.MusicGenrePath);
|
||||
|
||||
return new MusicGenresValidator(this, _userManager, _logger).Run(progress, cancellationToken);
|
||||
return new MusicGenresValidator(this, _logger).Run(progress, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -102,7 +102,9 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
if (query.IncludeArtists)
|
||||
{
|
||||
// Find artists
|
||||
var artists = _libraryManager.GetAllArtists(items)
|
||||
var artists = items.OfType<Audio>()
|
||||
.SelectMany(i => i.AllArtists)
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
|
||||
foreach (var item in artists)
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
using MediaBrowser.Common.Progress;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Model.Dto;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using System;
|
||||
@@ -69,10 +67,6 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
|
||||
|
||||
var numComplete = 0;
|
||||
|
||||
var userLibraries = _userManager.Users
|
||||
.Select(i => new Tuple<Guid, List<IHasArtist>>(i.Id, i.RootFolder.GetRecursiveChildren(i).OfType<IHasArtist>().ToList()))
|
||||
.ToList();
|
||||
|
||||
var numArtists = allArtists.Count;
|
||||
|
||||
foreach (var artist in allArtists)
|
||||
@@ -91,11 +85,6 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
|
||||
.ToList();
|
||||
}
|
||||
|
||||
foreach (var lib in userLibraries)
|
||||
{
|
||||
SetItemCounts(artist, lib.Item1, lib.Item2);
|
||||
}
|
||||
|
||||
numComplete++;
|
||||
double percent = numComplete;
|
||||
percent /= numArtists;
|
||||
@@ -107,37 +96,6 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
|
||||
progress.Report(100);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the item counts.
|
||||
/// </summary>
|
||||
/// <param name="artist">The artist.</param>
|
||||
/// <param name="userId">The user id.</param>
|
||||
/// <param name="allItems">All items.</param>
|
||||
private void SetItemCounts(MusicArtist artist, Guid? userId, IEnumerable<IHasArtist> allItems)
|
||||
{
|
||||
var name = artist.Name;
|
||||
|
||||
var items = allItems
|
||||
.Where(i => i.HasArtist(name))
|
||||
.ToList();
|
||||
|
||||
var counts = new ItemByNameCounts
|
||||
{
|
||||
TotalCount = items.Count,
|
||||
|
||||
SongCount = items.OfType<Audio>().Count(),
|
||||
|
||||
AlbumCount = items.OfType<MusicAlbum>().Count(),
|
||||
|
||||
MusicVideoCount = items.OfType<MusicVideo>().Count()
|
||||
};
|
||||
|
||||
if (userId.HasValue)
|
||||
{
|
||||
artist.SetItemByNameCounts(userId.Value, counts);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all artists.
|
||||
/// </summary>
|
||||
@@ -147,7 +105,8 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
|
||||
/// <returns>Task{Artist[]}.</returns>
|
||||
private async Task<List<MusicArtist>> GetAllArtists(IEnumerable<Audio> allSongs, CancellationToken cancellationToken, IProgress<double> progress)
|
||||
{
|
||||
var allArtists = _libraryManager.GetAllArtists(allSongs)
|
||||
var allArtists = allSongs.SelectMany(i => i.AllArtists)
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
|
||||
var returnArtists = new List<MusicArtist>(allArtists.Count);
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -41,38 +40,24 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
|
||||
/// <returns>Task.</returns>
|
||||
public async Task Run(IProgress<double> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
var userLibraries = _userManager.Users
|
||||
.Select(i => new Tuple<Guid, List<Game>>(i.Id, i.RootFolder.GetRecursiveChildren(i).OfType<Game>().ToList()))
|
||||
var items = _libraryManager.RootFolder.RecursiveChildren.Where(i => (i is Game))
|
||||
.SelectMany(i => i.Genres)
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
|
||||
var masterDictionary = new Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
progress.Report(2);
|
||||
|
||||
var numComplete = 0;
|
||||
var count = items.Count;
|
||||
|
||||
foreach (var lib in userLibraries)
|
||||
foreach (var name in items)
|
||||
{
|
||||
SetItemCounts(lib.Item1, lib.Item2, masterDictionary);
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
numComplete++;
|
||||
double percent = numComplete;
|
||||
percent /= userLibraries.Count;
|
||||
percent *= 8;
|
||||
|
||||
progress.Report(percent);
|
||||
}
|
||||
|
||||
progress.Report(10);
|
||||
|
||||
var count = masterDictionary.Count;
|
||||
numComplete = 0;
|
||||
|
||||
foreach (var name in masterDictionary.Keys)
|
||||
{
|
||||
try
|
||||
{
|
||||
await UpdateItemByNameCounts(name, cancellationToken, masterDictionary[name]).ConfigureAwait(false);
|
||||
var itemByName = _libraryManager.GetGameGenre(name);
|
||||
|
||||
await itemByName.RefreshMetadata(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
@@ -81,7 +66,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error updating counts for {0}", ex, name);
|
||||
_logger.ErrorException("Error refreshing {0}", ex, name);
|
||||
}
|
||||
|
||||
numComplete++;
|
||||
@@ -94,32 +79,5 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
|
||||
|
||||
progress.Report(100);
|
||||
}
|
||||
|
||||
private Task UpdateItemByNameCounts(string name, CancellationToken cancellationToken, Dictionary<Guid, Dictionary<CountType, int>> counts)
|
||||
{
|
||||
var itemByName = _libraryManager.GetGameGenre(name);
|
||||
|
||||
foreach (var libraryId in counts.Keys)
|
||||
{
|
||||
var itemCounts = CountHelpers.GetCounts(counts[libraryId]);
|
||||
|
||||
itemByName.SetItemByNameCounts(libraryId, itemCounts);
|
||||
}
|
||||
|
||||
return itemByName.RefreshMetadata(cancellationToken);
|
||||
}
|
||||
|
||||
private void SetItemCounts(Guid userId, IEnumerable<BaseItem> allItems, Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>> masterDictionary)
|
||||
{
|
||||
foreach (var media in allItems)
|
||||
{
|
||||
var names = media
|
||||
.Genres
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
|
||||
CountHelpers.SetItemCounts(userId, media, names, masterDictionary);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ using MediaBrowser.Controller.Entities.Audio;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -42,38 +41,24 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
|
||||
/// <returns>Task.</returns>
|
||||
public async Task Run(IProgress<double> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
var userLibraries = _userManager.Users
|
||||
.Select(i => new Tuple<Guid, IList<BaseItem>>(i.Id, i.RootFolder.GetRecursiveChildren(i, m => !(m is IHasMusicGenres) && !(m is Game))))
|
||||
var items = _libraryManager.RootFolder.RecursiveChildren.Where(i => !(i is IHasMusicGenres) && !(i is Game))
|
||||
.SelectMany(i => i.Genres)
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
|
||||
var masterDictionary = new Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
progress.Report(2);
|
||||
|
||||
var numComplete = 0;
|
||||
var count = items.Count;
|
||||
|
||||
foreach (var lib in userLibraries)
|
||||
foreach (var name in items)
|
||||
{
|
||||
SetItemCounts(lib.Item1, lib.Item2, masterDictionary);
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
numComplete++;
|
||||
double percent = numComplete;
|
||||
percent /= userLibraries.Count;
|
||||
percent *= 8;
|
||||
|
||||
progress.Report(percent);
|
||||
}
|
||||
|
||||
progress.Report(10);
|
||||
|
||||
var count = masterDictionary.Count;
|
||||
numComplete = 0;
|
||||
|
||||
foreach (var name in masterDictionary.Keys)
|
||||
{
|
||||
try
|
||||
{
|
||||
await UpdateItemByNameCounts(name, cancellationToken, masterDictionary[name]).ConfigureAwait(false);
|
||||
var itemByName = _libraryManager.GetGenre(name);
|
||||
|
||||
await itemByName.RefreshMetadata(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
@@ -82,7 +67,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error updating counts for {0}", ex, name);
|
||||
_logger.ErrorException("Error refreshing {0}", ex, name);
|
||||
}
|
||||
|
||||
numComplete++;
|
||||
@@ -95,32 +80,5 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
|
||||
|
||||
progress.Report(100);
|
||||
}
|
||||
|
||||
private Task UpdateItemByNameCounts(string name, CancellationToken cancellationToken, Dictionary<Guid, Dictionary<CountType, int>> counts)
|
||||
{
|
||||
var itemByName = _libraryManager.GetGenre(name);
|
||||
|
||||
foreach (var libraryId in counts.Keys)
|
||||
{
|
||||
var itemCounts = CountHelpers.GetCounts(counts[libraryId]);
|
||||
|
||||
itemByName.SetItemByNameCounts(libraryId, itemCounts);
|
||||
}
|
||||
|
||||
return itemByName.RefreshMetadata(cancellationToken);
|
||||
}
|
||||
|
||||
private void SetItemCounts(Guid userId, IEnumerable<BaseItem> allItems, Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>> masterDictionary)
|
||||
{
|
||||
foreach (var media in allItems)
|
||||
{
|
||||
var names = media
|
||||
.Genres
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
|
||||
CountHelpers.SetItemCounts(userId, media, names, masterDictionary);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -17,20 +15,14 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
|
||||
/// </summary>
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
|
||||
/// <summary>
|
||||
/// The _user manager
|
||||
/// </summary>
|
||||
private readonly IUserManager _userManager;
|
||||
|
||||
/// <summary>
|
||||
/// The _logger
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public MusicGenresValidator(ILibraryManager libraryManager, IUserManager userManager, ILogger logger)
|
||||
public MusicGenresValidator(ILibraryManager libraryManager, ILogger logger)
|
||||
{
|
||||
_libraryManager = libraryManager;
|
||||
_userManager = userManager;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@@ -42,38 +34,24 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
|
||||
/// <returns>Task.</returns>
|
||||
public async Task Run(IProgress<double> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
var userLibraries = _userManager.Users
|
||||
.Select(i => new Tuple<Guid, IList<BaseItem>>(i.Id, i.RootFolder.GetRecursiveChildren(i, m => m is IHasMusicGenres)))
|
||||
var items = _libraryManager.RootFolder.RecursiveChildren.Where(i => (i is IHasMusicGenres))
|
||||
.SelectMany(i => i.Genres)
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
|
||||
var masterDictionary = new Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
progress.Report(2);
|
||||
|
||||
var numComplete = 0;
|
||||
var count = items.Count;
|
||||
|
||||
foreach (var lib in userLibraries)
|
||||
foreach (var name in items)
|
||||
{
|
||||
SetItemCounts(lib.Item1, lib.Item2, masterDictionary);
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
numComplete++;
|
||||
double percent = numComplete;
|
||||
percent /= userLibraries.Count;
|
||||
percent *= 8;
|
||||
|
||||
progress.Report(percent);
|
||||
}
|
||||
|
||||
progress.Report(10);
|
||||
|
||||
var count = masterDictionary.Count;
|
||||
numComplete = 0;
|
||||
|
||||
foreach (var name in masterDictionary.Keys)
|
||||
{
|
||||
try
|
||||
{
|
||||
await UpdateItemByNameCounts(name, cancellationToken, masterDictionary[name]).ConfigureAwait(false);
|
||||
var itemByName = _libraryManager.GetMusicGenre(name);
|
||||
|
||||
await itemByName.RefreshMetadata(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
@@ -82,7 +60,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error updating counts for {0}", ex, name);
|
||||
_logger.ErrorException("Error refreshing {0}", ex, name);
|
||||
}
|
||||
|
||||
numComplete++;
|
||||
@@ -95,32 +73,5 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
|
||||
|
||||
progress.Report(100);
|
||||
}
|
||||
|
||||
private Task UpdateItemByNameCounts(string name, CancellationToken cancellationToken, Dictionary<Guid, Dictionary<CountType, int>> counts)
|
||||
{
|
||||
var itemByName = _libraryManager.GetMusicGenre(name);
|
||||
|
||||
foreach (var libraryId in counts.Keys)
|
||||
{
|
||||
var itemCounts = CountHelpers.GetCounts(counts[libraryId]);
|
||||
|
||||
itemByName.SetItemByNameCounts(libraryId, itemCounts);
|
||||
}
|
||||
|
||||
return itemByName.RefreshMetadata(cancellationToken);
|
||||
}
|
||||
|
||||
private void SetItemCounts(Guid userId, IEnumerable<BaseItem> allItems, Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>> masterDictionary)
|
||||
{
|
||||
foreach (var media in allItems)
|
||||
{
|
||||
var names = media
|
||||
.Genres
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
|
||||
CountHelpers.SetItemCounts(userId, media, names, masterDictionary);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -17,20 +14,14 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
|
||||
/// </summary>
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
|
||||
/// <summary>
|
||||
/// The _user manager
|
||||
/// </summary>
|
||||
private readonly IUserManager _userManager;
|
||||
|
||||
/// <summary>
|
||||
/// The _logger
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public PeoplePostScanTask(ILibraryManager libraryManager, IUserManager userManager, ILogger logger)
|
||||
public PeoplePostScanTask(ILibraryManager libraryManager, ILogger logger)
|
||||
{
|
||||
_libraryManager = libraryManager;
|
||||
_userManager = userManager;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@@ -42,94 +33,12 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
|
||||
/// <returns>Task.</returns>
|
||||
public Task Run(IProgress<double> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
return RunInternal(progress, cancellationToken);
|
||||
}
|
||||
|
||||
private async Task RunInternal(IProgress<double> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
var userLibraries = _userManager.Users
|
||||
.Select(i => new Tuple<Guid, IList<BaseItem>>(i.Id, i.RootFolder.GetRecursiveChildren(i, null)))
|
||||
.ToList();
|
||||
|
||||
var masterDictionary = new Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
progress.Report(2);
|
||||
|
||||
var numComplete = 0;
|
||||
|
||||
foreach (var lib in userLibraries)
|
||||
return new PeopleValidator(_libraryManager, _logger).ValidatePeople(cancellationToken, new MetadataRefreshOptions
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ImageRefreshMode = ImageRefreshMode.ValidationOnly,
|
||||
MetadataRefreshMode = MetadataRefreshMode.None
|
||||
|
||||
SetItemCounts(lib.Item1, lib.Item2, masterDictionary);
|
||||
|
||||
numComplete++;
|
||||
double percent = numComplete;
|
||||
percent /= userLibraries.Count;
|
||||
percent *= 8;
|
||||
|
||||
progress.Report(percent);
|
||||
}
|
||||
|
||||
progress.Report(10);
|
||||
|
||||
var count = masterDictionary.Count;
|
||||
numComplete = 0;
|
||||
|
||||
foreach (var name in masterDictionary.Keys)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
try
|
||||
{
|
||||
var counts = masterDictionary[name];
|
||||
|
||||
var itemByName = _libraryManager.GetPerson(name);
|
||||
|
||||
// The only purpose here is to be able to react to image changes without running the people task.
|
||||
// All other metadata can wait for that.
|
||||
await itemByName.RefreshMetadata(new MetadataRefreshOptions
|
||||
{
|
||||
ImageRefreshMode = ImageRefreshMode.ValidationOnly,
|
||||
MetadataRefreshMode = MetadataRefreshMode.None
|
||||
|
||||
}, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
foreach (var libraryId in counts.Keys)
|
||||
{
|
||||
var itemCounts = CountHelpers.GetCounts(counts[libraryId]);
|
||||
|
||||
itemByName.SetItemByNameCounts(libraryId, itemCounts);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error updating counts for {0}", ex, name);
|
||||
}
|
||||
|
||||
numComplete++;
|
||||
double percent = numComplete;
|
||||
percent /= count;
|
||||
percent *= 90;
|
||||
|
||||
progress.Report(percent + 10);
|
||||
}
|
||||
|
||||
progress.Report(100);
|
||||
}, progress);
|
||||
}
|
||||
|
||||
private void SetItemCounts(Guid userId, IEnumerable<BaseItem> allItems, Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>> masterDictionary)
|
||||
{
|
||||
foreach (var media in allItems)
|
||||
{
|
||||
var names = media
|
||||
.People.Select(i => i.Name)
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
|
||||
CountHelpers.SetItemCounts(userId, media, names, masterDictionary);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using MediaBrowser.Common.Progress;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MoreLinq;
|
||||
using System;
|
||||
@@ -38,9 +39,10 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
|
||||
/// Validates the people.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <param name="options">The options.</param>
|
||||
/// <param name="progress">The progress.</param>
|
||||
/// <returns>Task.</returns>
|
||||
public async Task ValidatePeople(CancellationToken cancellationToken, IProgress<double> progress)
|
||||
public async Task ValidatePeople(CancellationToken cancellationToken, MetadataRefreshOptions options, IProgress<double> progress)
|
||||
{
|
||||
var innerProgress = new ActionableProgress<double>();
|
||||
|
||||
@@ -61,7 +63,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
|
||||
{
|
||||
var item = _libraryManager.GetPerson(person.Name);
|
||||
|
||||
await item.RefreshMetadata(cancellationToken).ConfigureAwait(false);
|
||||
await item.RefreshMetadata(options, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -41,38 +39,24 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
|
||||
/// <returns>Task.</returns>
|
||||
public async Task Run(IProgress<double> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
var userLibraries = _userManager.Users
|
||||
.Select(i => new Tuple<Guid, IList<BaseItem>>(i.Id, i.RootFolder.GetRecursiveChildren(i, null)))
|
||||
var items = _libraryManager.RootFolder.RecursiveChildren
|
||||
.SelectMany(i => i.Studios)
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
|
||||
var masterDictionary = new Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
progress.Report(2);
|
||||
|
||||
var numComplete = 0;
|
||||
var count = items.Count;
|
||||
|
||||
foreach (var lib in userLibraries)
|
||||
foreach (var name in items)
|
||||
{
|
||||
SetItemCounts(lib.Item1, lib.Item2, masterDictionary);
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
numComplete++;
|
||||
double percent = numComplete;
|
||||
percent /= userLibraries.Count;
|
||||
percent *= 8;
|
||||
|
||||
progress.Report(percent);
|
||||
}
|
||||
|
||||
progress.Report(10);
|
||||
|
||||
var count = masterDictionary.Count;
|
||||
numComplete = 0;
|
||||
|
||||
foreach (var name in masterDictionary.Keys)
|
||||
{
|
||||
try
|
||||
{
|
||||
await UpdateItemByNameCounts(name, cancellationToken, masterDictionary[name]).ConfigureAwait(false);
|
||||
var itemByName = _libraryManager.GetStudio(name);
|
||||
|
||||
await itemByName.RefreshMetadata(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
@@ -81,7 +65,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error updating counts for {0}", ex, name);
|
||||
_logger.ErrorException("Error refreshing {0}", ex, name);
|
||||
}
|
||||
|
||||
numComplete++;
|
||||
@@ -94,32 +78,5 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
|
||||
|
||||
progress.Report(100);
|
||||
}
|
||||
|
||||
private Task UpdateItemByNameCounts(string name, CancellationToken cancellationToken, Dictionary<Guid, Dictionary<CountType, int>> counts)
|
||||
{
|
||||
var itemByName = _libraryManager.GetStudio(name);
|
||||
|
||||
foreach (var libraryId in counts.Keys)
|
||||
{
|
||||
var itemCounts = CountHelpers.GetCounts(counts[libraryId]);
|
||||
|
||||
itemByName.SetItemByNameCounts(libraryId, itemCounts);
|
||||
}
|
||||
|
||||
return itemByName.RefreshMetadata(cancellationToken);
|
||||
}
|
||||
|
||||
private void SetItemCounts(Guid userId, IEnumerable<BaseItem> allItems, Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>> masterDictionary)
|
||||
{
|
||||
foreach (var media in allItems)
|
||||
{
|
||||
var names = media
|
||||
.Studios
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
|
||||
CountHelpers.SetItemCounts(userId, media, names, masterDictionary);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user