diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2013-09-11 13:54:59 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2013-09-11 13:54:59 -0400 |
| commit | 803e8b4a2eb5fcf1b5a3679fe551d541620d4743 (patch) | |
| tree | 8d070a411db7406fe5e7f30e03feefe83ad7127d /MediaBrowser.Server.Implementations/Library | |
| parent | 1496991096c4db9f69bc572aeefc8099ca0f0c01 (diff) | |
improved performance of item counts
Diffstat (limited to 'MediaBrowser.Server.Implementations/Library')
10 files changed, 155 insertions, 153 deletions
diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index d017a5f7e..602f81c33 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -581,6 +581,11 @@ namespace MediaBrowser.Server.Implementations.Library (UserRootFolder)ResolvePath(new DirectoryInfo(userRootPath))); } + public Person GetPersonSync(string name) + { + return GetItemByName<Person>(ConfigurationManager.ApplicationPaths.PeoplePath, name); + } + /// <summary> /// Gets a Person /// </summary> @@ -752,6 +757,37 @@ namespace MediaBrowser.Server.Implementations.Library /// </summary> private readonly ConcurrentDictionary<string, BaseItem> _itemsByName = new ConcurrentDictionary<string, BaseItem>(StringComparer.OrdinalIgnoreCase); + private T GetItemByName<T>(string path, string name) + where T : BaseItem, new() + { + if (string.IsNullOrEmpty(path)) + { + throw new ArgumentNullException(); + } + + if (string.IsNullOrEmpty(name)) + { + throw new ArgumentNullException(); + } + + var validFilename = FileSystem.GetValidFilename(name); + + var key = Path.Combine(path, validFilename); + + BaseItem obj; + + if (!_itemsByName.TryGetValue(key, out obj)) + { + var tuple = CreateItemByName<T>(key, name); + + obj = tuple.Item2; + + _itemsByName.AddOrUpdate(key, obj, (keyName, oldValue) => obj); + } + + return obj as T; + } + /// <summary> /// Generically retrieves an IBN item /// </summary> @@ -777,13 +813,15 @@ namespace MediaBrowser.Server.Implementations.Library throw new ArgumentNullException(); } - var key = Path.Combine(path, FileSystem.GetValidFilename(name)); + var validFilename = FileSystem.GetValidFilename(name); + + var key = Path.Combine(path, validFilename); BaseItem obj; if (!_itemsByName.TryGetValue(key, out obj)) { - var tuple = CreateItemByName<T>(path, name, cancellationToken); + var tuple = CreateItemByName<T>(key, name); obj = tuple.Item2; @@ -815,16 +853,11 @@ namespace MediaBrowser.Server.Implementations.Library /// <typeparam name="T"></typeparam> /// <param name="path">The path.</param> /// <param name="name">The name.</param> - /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Task{``0}.</returns> /// <exception cref="System.IO.IOException">Path not created: + path</exception> - private Tuple<bool, T> CreateItemByName<T>(string path, string name, CancellationToken cancellationToken) + private Tuple<bool, T> CreateItemByName<T>(string path, string name) where T : BaseItem, new() { - cancellationToken.ThrowIfCancellationRequested(); - - path = Path.Combine(path, FileSystem.GetValidFilename(name)); - var fileInfo = new DirectoryInfo(path); var isNew = false; @@ -842,8 +875,6 @@ namespace MediaBrowser.Server.Implementations.Library isNew = true; } - cancellationToken.ThrowIfCancellationRequested(); - var type = typeof(T); var id = path.GetMBId(type); @@ -866,7 +897,7 @@ namespace MediaBrowser.Server.Implementations.Library // Set this now so we don't cause additional file system access during provider executions item.ResetResolveArgs(fileInfo); - return new Tuple<bool,T>(isNew, item); + return new Tuple<bool, T>(isNew, item); } /// <summary> @@ -878,16 +909,12 @@ namespace MediaBrowser.Server.Implementations.Library /// <returns>Task.</returns> public async Task ValidatePeople(CancellationToken cancellationToken, IProgress<double> progress) { - const int maxTasks = 10; + const int maxTasks = 5; var tasks = new List<Task>(); - var includedPersonTypes = new[] { PersonType.Actor, PersonType.Director, PersonType.GuestStar, PersonType.Writer, PersonType.Producer } - .ToDictionary(i => i, StringComparer.OrdinalIgnoreCase); - var people = RootFolder.RecursiveChildren - .Where(c => c.People != null) - .SelectMany(c => c.People.Where(p => includedPersonTypes.ContainsKey(p.Type ?? string.Empty) || includedPersonTypes.ContainsKey(p.Role ?? string.Empty))) + .SelectMany(c => c.People) .DistinctBy(p => p.Name, StringComparer.OrdinalIgnoreCase) .ToList(); @@ -1050,6 +1077,10 @@ namespace MediaBrowser.Server.Implementations.Library await RunPostScanTasks(progress, cancellationToken).ConfigureAwait(false); progress.Report(100); + + // Bad practice, i know. But we keep a lot in memory, unfortunately. + GC.Collect(2, GCCollectionMode.Forced, true); + GC.Collect(2, GCCollectionMode.Forced, true); } /// <summary> diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/AudioResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/AudioResolver.cs index 485784397..3c6cc654f 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/AudioResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/AudioResolver.cs @@ -30,10 +30,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio { if (EntityResolutionHelper.IsAudioFile(args.Path)) { - return new Controller.Entities.Audio.Audio - { - DisplayMediaType = "Song" - }; + return new Controller.Entities.Audio.Audio(); } } diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs index e35352407..73c26dd64 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs @@ -46,11 +46,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio return null; } - return IsMusicAlbum(args) ? new MusicAlbum - { - DisplayMediaType = "Album" - - } : null; + return IsMusicAlbum(args) ? new MusicAlbum() : null; } diff --git a/MediaBrowser.Server.Implementations/Library/Validators/ArtistsValidator.cs b/MediaBrowser.Server.Implementations/Library/Validators/ArtistsValidator.cs index 8109208e7..54d816cb0 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/ArtistsValidator.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/ArtistsValidator.cs @@ -108,7 +108,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators } // Populate counts of items - SetItemCounts(artist, null, allItems.OfType<IHasArtist>()); + //SetItemCounts(artist, null, allItems.OfType<IHasArtist>()); foreach (var lib in userLibraries) { @@ -155,10 +155,6 @@ namespace MediaBrowser.Server.Implementations.Library.Validators { artist.UserItemCounts[userId.Value] = counts; } - else - { - artist.ItemCounts = counts; - } } /// <summary> diff --git a/MediaBrowser.Server.Implementations/Library/Validators/CountHelpers.cs b/MediaBrowser.Server.Implementations/Library/Validators/CountHelpers.cs index ea4d887ea..084d720ae 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/CountHelpers.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/CountHelpers.cs @@ -18,46 +18,46 @@ namespace MediaBrowser.Server.Implementations.Library.Validators /// </summary> /// <param name="item">The item.</param> /// <param name="counts">The counts.</param> - internal static void AddToDictionary(BaseItem item, Dictionary<string, int> counts) + internal static void AddToDictionary(BaseItem item, Dictionary<CountType, int> counts) { if (item is Movie) { - IncrementCount(counts, "Movie"); + IncrementCount(counts, CountType.Movie); } else if (item is Trailer) { - IncrementCount(counts, "Trailer"); + IncrementCount(counts, CountType.Trailer); } else if (item is Series) { - IncrementCount(counts, "Series"); + IncrementCount(counts, CountType.Series); } else if (item is Game) { - IncrementCount(counts, "Game"); + IncrementCount(counts, CountType.Game); } else if (item is Audio) { - IncrementCount(counts, "Audio"); + IncrementCount(counts, CountType.Song); } else if (item is MusicAlbum) { - IncrementCount(counts, "MusicAlbum"); + IncrementCount(counts, CountType.MusicAlbum); } else if (item is Episode) { - IncrementCount(counts, "Episode"); + IncrementCount(counts, CountType.Episode); } else if (item is MusicVideo) { - IncrementCount(counts, "MusicVideo"); + IncrementCount(counts, CountType.MusicVideo); } else if (item is AdultVideo) { - IncrementCount(counts, "AdultVideo"); + IncrementCount(counts, CountType.AdultVideo); } - IncrementCount(counts, "Total"); + IncrementCount(counts, CountType.Total); } /// <summary> @@ -65,7 +65,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators /// </summary> /// <param name="counts">The counts.</param> /// <param name="key">The key.</param> - internal static void IncrementCount(Dictionary<string, int> counts, string key) + internal static void IncrementCount(Dictionary<CountType, int> counts, CountType key) { int count; @@ -85,20 +85,20 @@ namespace MediaBrowser.Server.Implementations.Library.Validators /// </summary> /// <param name="counts">The counts.</param> /// <returns>ItemByNameCounts.</returns> - internal static ItemByNameCounts GetCounts(Dictionary<string, int> counts) + internal static ItemByNameCounts GetCounts(Dictionary<CountType, int> counts) { return new ItemByNameCounts { - AdultVideoCount = GetCount(counts, "AdultVideo"), - AlbumCount = GetCount(counts, "MusicAlbum"), - EpisodeCount = GetCount(counts, "Episode"), - GameCount = GetCount(counts, "Game"), - MovieCount = GetCount(counts, "Movie"), - MusicVideoCount = GetCount(counts, "MusicVideo"), - SeriesCount = GetCount(counts, "Series"), - SongCount = GetCount(counts, "Audio"), - TrailerCount = GetCount(counts, "Trailer"), - TotalCount = GetCount(counts, "Total") + AdultVideoCount = GetCount(counts, CountType.AdultVideo), + AlbumCount = GetCount(counts, CountType.MusicAlbum), + EpisodeCount = GetCount(counts, CountType.Episode), + GameCount = GetCount(counts, CountType.Game), + MovieCount = GetCount(counts, CountType.Movie), + MusicVideoCount = GetCount(counts, CountType.MusicVideo), + SeriesCount = GetCount(counts, CountType.Series), + SongCount = GetCount(counts, CountType.Song), + TrailerCount = GetCount(counts, CountType.Trailer), + TotalCount = GetCount(counts, CountType.Total) }; } @@ -108,7 +108,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators /// <param name="counts">The counts.</param> /// <param name="key">The key.</param> /// <returns>System.Int32.</returns> - internal static int GetCount(Dictionary<string, int> counts, string key) + internal static int GetCount(Dictionary<CountType, int> counts, CountType key) { int count; @@ -127,24 +127,24 @@ namespace MediaBrowser.Server.Implementations.Library.Validators /// <param name="media">The media.</param> /// <param name="names">The names.</param> /// <param name="masterDictionary">The master dictionary.</param> - internal static void SetItemCounts(Guid? userId, BaseItem media, List<string> names, Dictionary<string, Dictionary<Guid, Dictionary<string, int>>> masterDictionary) + internal static void SetItemCounts(Guid userId, BaseItem media, List<string> names, Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>> masterDictionary) { foreach (var name in names) { - Dictionary<Guid, Dictionary<string, int>> libraryCounts; + Dictionary<Guid, Dictionary<CountType, int>> libraryCounts; if (!masterDictionary.TryGetValue(name, out libraryCounts)) { - libraryCounts = new Dictionary<Guid, Dictionary<string, int>>(); + libraryCounts = new Dictionary<Guid, Dictionary<CountType, int>>(); masterDictionary.Add(name, libraryCounts); } - var userLibId = userId ?? Guid.Empty; - Dictionary<string, int> userDictionary; + var userLibId = userId/* ?? Guid.Empty*/; + Dictionary<CountType, int> userDictionary; if (!libraryCounts.TryGetValue(userLibId, out userDictionary)) { - userDictionary = new Dictionary<string, int>(); + userDictionary = new Dictionary<CountType, int>(); libraryCounts.Add(userLibId, userDictionary); } @@ -152,4 +152,18 @@ namespace MediaBrowser.Server.Implementations.Library.Validators } } } + + internal enum CountType + { + AdultVideo, + MusicAlbum, + Episode, + Game, + Movie, + MusicVideo, + Series, + Song, + Trailer, + Total + } } diff --git a/MediaBrowser.Server.Implementations/Library/Validators/GameGenresValidator.cs b/MediaBrowser.Server.Implementations/Library/Validators/GameGenresValidator.cs index f8aeadda1..eba7193e0 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/GameGenresValidator.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/GameGenresValidator.cs @@ -49,10 +49,10 @@ namespace MediaBrowser.Server.Implementations.Library.Validators var allLibraryItems = allItems; - var masterDictionary = new Dictionary<string, Dictionary<Guid, Dictionary<string, int>>>(StringComparer.OrdinalIgnoreCase); + var masterDictionary = new Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>>(StringComparer.OrdinalIgnoreCase); // Populate counts of items - SetItemCounts(null, allLibraryItems, masterDictionary); + //SetItemCounts(null, allLibraryItems, masterDictionary); progress.Report(2); @@ -72,10 +72,10 @@ namespace MediaBrowser.Server.Implementations.Library.Validators progress.Report(10); - var names = masterDictionary.Keys.ToList(); + var count = masterDictionary.Count; numComplete = 0; - foreach (var name in names) + foreach (var name in masterDictionary.Keys) { try { @@ -88,7 +88,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators numComplete++; double percent = numComplete; - percent /= names.Count; + percent /= count; percent *= 90; progress.Report(percent + 10); @@ -97,26 +97,19 @@ namespace MediaBrowser.Server.Implementations.Library.Validators progress.Report(100); } - private async Task UpdateItemByNameCounts(string name, CancellationToken cancellationToken, Dictionary<Guid, Dictionary<string, int>> counts) + private async Task UpdateItemByNameCounts(string name, CancellationToken cancellationToken, Dictionary<Guid, Dictionary<CountType, int>> counts) { var itemByName = await _libraryManager.GetGameGenre(name, cancellationToken, true, true).ConfigureAwait(false); - foreach (var libraryId in counts.Keys.ToList()) + foreach (var libraryId in counts.Keys) { var itemCounts = CountHelpers.GetCounts(counts[libraryId]); - if (libraryId == Guid.Empty) - { - itemByName.ItemCounts = itemCounts; - } - else - { - itemByName.UserItemCounts[libraryId] = itemCounts; - } + itemByName.UserItemCounts[libraryId] = itemCounts; } } - private void SetItemCounts(Guid? userId, IEnumerable<BaseItem> allItems, Dictionary<string, Dictionary<Guid, Dictionary<string, int>>> masterDictionary) + private void SetItemCounts(Guid userId, IEnumerable<BaseItem> allItems, Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>> masterDictionary) { foreach (var media in allItems) { diff --git a/MediaBrowser.Server.Implementations/Library/Validators/GenresValidator.cs b/MediaBrowser.Server.Implementations/Library/Validators/GenresValidator.cs index 852984a5c..c605961f7 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/GenresValidator.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/GenresValidator.cs @@ -52,10 +52,10 @@ namespace MediaBrowser.Server.Implementations.Library.Validators var allLibraryItems = allItems; - var masterDictionary = new Dictionary<string, Dictionary<Guid, Dictionary<string, int>>>(StringComparer.OrdinalIgnoreCase); + var masterDictionary = new Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>>(StringComparer.OrdinalIgnoreCase); // Populate counts of items - SetItemCounts(null, allLibraryItems, masterDictionary); + //SetItemCounts(null, allLibraryItems, masterDictionary); progress.Report(2); @@ -75,10 +75,10 @@ namespace MediaBrowser.Server.Implementations.Library.Validators progress.Report(10); - var names = masterDictionary.Keys.ToList(); + var count = masterDictionary.Count; numComplete = 0; - foreach (var name in names) + foreach (var name in masterDictionary.Keys) { try { @@ -91,7 +91,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators numComplete++; double percent = numComplete; - percent /= names.Count; + percent /= count; percent *= 90; progress.Report(percent + 10); @@ -100,26 +100,19 @@ namespace MediaBrowser.Server.Implementations.Library.Validators progress.Report(100); } - private async Task UpdateItemByNameCounts(string name, CancellationToken cancellationToken, Dictionary<Guid, Dictionary<string, int>> counts) + private async Task UpdateItemByNameCounts(string name, CancellationToken cancellationToken, Dictionary<Guid, Dictionary<CountType, int>> counts) { var itemByName = await _libraryManager.GetGenre(name, cancellationToken, true, true).ConfigureAwait(false); - foreach (var libraryId in counts.Keys.ToList()) + foreach (var libraryId in counts.Keys) { var itemCounts = CountHelpers.GetCounts(counts[libraryId]); - if (libraryId == Guid.Empty) - { - itemByName.ItemCounts = itemCounts; - } - else - { - itemByName.UserItemCounts[libraryId] = itemCounts; - } + itemByName.UserItemCounts[libraryId] = itemCounts; } } - private void SetItemCounts(Guid? userId, IEnumerable<BaseItem> allItems, Dictionary<string, Dictionary<Guid, Dictionary<string, int>>> masterDictionary) + private void SetItemCounts(Guid userId, IEnumerable<BaseItem> allItems, Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>> masterDictionary) { foreach (var media in allItems) { diff --git a/MediaBrowser.Server.Implementations/Library/Validators/MusicGenresValidator.cs b/MediaBrowser.Server.Implementations/Library/Validators/MusicGenresValidator.cs index 53e443527..9063027ec 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/MusicGenresValidator.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/MusicGenresValidator.cs @@ -52,10 +52,10 @@ namespace MediaBrowser.Server.Implementations.Library.Validators var allLibraryItems = allItems; - var masterDictionary = new Dictionary<string, Dictionary<Guid, Dictionary<string, int>>>(StringComparer.OrdinalIgnoreCase); + var masterDictionary = new Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>>(StringComparer.OrdinalIgnoreCase); // Populate counts of items - SetItemCounts(null, allLibraryItems, masterDictionary); + //SetItemCounts(null, allLibraryItems, masterDictionary); progress.Report(2); @@ -75,10 +75,10 @@ namespace MediaBrowser.Server.Implementations.Library.Validators progress.Report(10); - var names = masterDictionary.Keys.ToList(); + var count = masterDictionary.Count; numComplete = 0; - foreach (var name in names) + foreach (var name in masterDictionary.Keys) { try { @@ -91,7 +91,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators numComplete++; double percent = numComplete; - percent /= names.Count; + percent /= count; percent *= 90; progress.Report(percent + 10); @@ -100,26 +100,19 @@ namespace MediaBrowser.Server.Implementations.Library.Validators progress.Report(100); } - private async Task UpdateItemByNameCounts(string name, CancellationToken cancellationToken, Dictionary<Guid, Dictionary<string, int>> counts) + private async Task UpdateItemByNameCounts(string name, CancellationToken cancellationToken, Dictionary<Guid, Dictionary<CountType, int>> counts) { var itemByName = await _libraryManager.GetMusicGenre(name, cancellationToken, true, true).ConfigureAwait(false); - foreach (var libraryId in counts.Keys.ToList()) + foreach (var libraryId in counts.Keys) { var itemCounts = CountHelpers.GetCounts(counts[libraryId]); - if (libraryId == Guid.Empty) - { - itemByName.ItemCounts = itemCounts; - } - else - { - itemByName.UserItemCounts[libraryId] = itemCounts; - } + itemByName.UserItemCounts[libraryId] = itemCounts; } } - private void SetItemCounts(Guid? userId, IEnumerable<BaseItem> allItems, Dictionary<string, Dictionary<Guid, Dictionary<string, int>>> masterDictionary) + private void SetItemCounts(Guid userId, IEnumerable<BaseItem> allItems, Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>> masterDictionary) { foreach (var media in allItems) { diff --git a/MediaBrowser.Server.Implementations/Library/Validators/PeoplePostScanTask.cs b/MediaBrowser.Server.Implementations/Library/Validators/PeoplePostScanTask.cs index 7d7728030..708f8bfa4 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/PeoplePostScanTask.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/PeoplePostScanTask.cs @@ -39,7 +39,13 @@ namespace MediaBrowser.Server.Implementations.Library.Validators /// <param name="progress">The progress.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Task.</returns> - public async Task Run(IProgress<double> progress, CancellationToken cancellationToken) + public Task Run(IProgress<double> progress, CancellationToken cancellationToken) + { + return RunInternal(progress, cancellationToken); + //return Task.Run(() => RunInternal(progress, cancellationToken)); + } + + private async Task RunInternal(IProgress<double> progress, CancellationToken cancellationToken) { var allItems = _libraryManager.RootFolder.RecursiveChildren.ToList(); @@ -49,10 +55,10 @@ namespace MediaBrowser.Server.Implementations.Library.Validators var allLibraryItems = allItems; - var masterDictionary = new Dictionary<string, Dictionary<Guid, Dictionary<string, int>>>(StringComparer.OrdinalIgnoreCase); + var masterDictionary = new Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>>(StringComparer.OrdinalIgnoreCase); // Populate counts of items - SetItemCounts(null, allLibraryItems, masterDictionary); + //SetItemCounts(null, allLibraryItems, masterDictionary); progress.Report(2); @@ -74,16 +80,25 @@ namespace MediaBrowser.Server.Implementations.Library.Validators progress.Report(10); - var names = masterDictionary.Keys.ToList(); + var count = masterDictionary.Count; numComplete = 0; - foreach (var name in names) + foreach (var name in masterDictionary.Keys) { cancellationToken.ThrowIfCancellationRequested(); - + try { - await UpdateItemByNameCounts(name, masterDictionary[name]).ConfigureAwait(false); + var counts = masterDictionary[name]; + + var itemByName = await _libraryManager.GetPerson(name).ConfigureAwait(false); + + foreach (var libraryId in counts.Keys) + { + var itemCounts = CountHelpers.GetCounts(counts[libraryId]); + + itemByName.UserItemCounts[libraryId] = itemCounts; + } } catch (Exception ex) { @@ -92,7 +107,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators numComplete++; double percent = numComplete; - percent /= names.Count; + percent /= count; percent *= 90; progress.Report(percent + 10); @@ -101,26 +116,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators progress.Report(100); } - private async Task UpdateItemByNameCounts(string name, Dictionary<Guid, Dictionary<string, int>> counts) - { - var itemByName = await _libraryManager.GetPerson(name).ConfigureAwait(false); - - foreach (var libraryId in counts.Keys.ToList()) - { - var itemCounts = CountHelpers.GetCounts(counts[libraryId]); - - if (libraryId == Guid.Empty) - { - itemByName.ItemCounts = itemCounts; - } - else - { - itemByName.UserItemCounts[libraryId] = itemCounts; - } - } - } - - private void SetItemCounts(Guid? userId, IEnumerable<BaseItem> allItems, Dictionary<string, Dictionary<Guid, Dictionary<string, int>>> masterDictionary) + private void SetItemCounts(Guid userId, IEnumerable<BaseItem> allItems, Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>> masterDictionary) { foreach (var media in allItems) { diff --git a/MediaBrowser.Server.Implementations/Library/Validators/StudiosValidator.cs b/MediaBrowser.Server.Implementations/Library/Validators/StudiosValidator.cs index 1814e7c4f..202cd9414 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/StudiosValidator.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/StudiosValidator.cs @@ -49,10 +49,10 @@ namespace MediaBrowser.Server.Implementations.Library.Validators var allLibraryItems = allItems; - var masterDictionary = new Dictionary<string, Dictionary<Guid, Dictionary<string, int>>>(StringComparer.OrdinalIgnoreCase); + var masterDictionary = new Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>>(StringComparer.OrdinalIgnoreCase); // Populate counts of items - SetItemCounts(null, allLibraryItems, masterDictionary); + //SetItemCounts(null, allLibraryItems, masterDictionary); progress.Report(2); @@ -72,10 +72,10 @@ namespace MediaBrowser.Server.Implementations.Library.Validators progress.Report(10); - var names = masterDictionary.Keys.ToList(); + var count = masterDictionary.Count; numComplete = 0; - foreach (var name in names) + foreach (var name in masterDictionary.Keys) { try { @@ -88,7 +88,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators numComplete++; double percent = numComplete; - percent /= names.Count; + percent /= count; percent *= 90; progress.Report(percent + 10); @@ -97,26 +97,19 @@ namespace MediaBrowser.Server.Implementations.Library.Validators progress.Report(100); } - private async Task UpdateItemByNameCounts(string name, CancellationToken cancellationToken, Dictionary<Guid, Dictionary<string, int>> counts) + private async Task UpdateItemByNameCounts(string name, CancellationToken cancellationToken, Dictionary<Guid, Dictionary<CountType, int>> counts) { var itemByName = await _libraryManager.GetStudio(name, cancellationToken, true, true).ConfigureAwait(false); - foreach (var libraryId in counts.Keys.ToList()) + foreach (var libraryId in counts.Keys) { var itemCounts = CountHelpers.GetCounts(counts[libraryId]); - if (libraryId == Guid.Empty) - { - itemByName.ItemCounts = itemCounts; - } - else - { - itemByName.UserItemCounts[libraryId] = itemCounts; - } + itemByName.UserItemCounts[libraryId] = itemCounts; } } - private void SetItemCounts(Guid? userId, IEnumerable<BaseItem> allItems, Dictionary<string, Dictionary<Guid, Dictionary<string, int>>> masterDictionary) + private void SetItemCounts(Guid userId, IEnumerable<BaseItem> allItems, Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>> masterDictionary) { foreach (var media in allItems) { |
