improved performance of item counts

This commit is contained in:
Luke Pulverenti
2013-09-11 13:54:59 -04:00
parent 1496991096
commit 803e8b4a2e
49 changed files with 496 additions and 380 deletions

View File

@@ -137,7 +137,8 @@ namespace MediaBrowser.Server.Implementations.Dto
if (user == null)
{
counts = item.ItemCounts;
//counts = item.ItemCounts;
return;
}
else
{
@@ -376,7 +377,7 @@ namespace MediaBrowser.Server.Implementations.Dto
}
dto.Album = item.Album;
dto.Artists = string.IsNullOrEmpty(item.Artist) ? new string[] { } : new[] { item.Artist };
dto.Artists = string.IsNullOrEmpty(item.Artist) ? new List<string>() : new List<string> { item.Artist };
}
private void SetGameProperties(BaseItemDto dto, Game item)
@@ -804,6 +805,7 @@ namespace MediaBrowser.Server.Implementations.Dto
dto.Language = item.Language;
dto.MediaType = item.MediaType;
dto.LocationType = item.LocationType;
dto.CriticRating = item.CriticRating;
if (fields.Contains(ItemFields.CriticRatingSummary))
@@ -938,7 +940,7 @@ namespace MediaBrowser.Server.Implementations.Dto
if (audio != null)
{
dto.Album = audio.Album;
dto.Artists = audio.Artists.ToArray();
dto.Artists = audio.Artists;
var albumParent = audio.FindParent<MusicAlbum>();

View File

@@ -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>

View File

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

View File

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

View File

@@ -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>

View File

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

View File

@@ -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)
{

View File

@@ -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)
{

View File

@@ -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)
{

View File

@@ -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)
{

View File

@@ -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)
{

View File

@@ -14,7 +14,12 @@ namespace MediaBrowser.Server.Implementations.Sorting
/// <returns>System.Int32.</returns>
public int Compare(BaseItem x, BaseItem y)
{
return (x.Budget ?? 0).CompareTo(y.Budget ?? 0);
return GetValue(x).CompareTo(GetValue(y));
}
private double GetValue(BaseItem x)
{
return x.Budget ?? 0;
}
/// <summary>

View File

@@ -17,7 +17,12 @@ namespace MediaBrowser.Server.Implementations.Sorting
/// <returns>System.Int32.</returns>
public int Compare(BaseItem x, BaseItem y)
{
return (x.CriticRating ?? 0).CompareTo(y.CriticRating ?? 0);
return GetValue(x).CompareTo(GetValue(y));
}
private float GetValue(BaseItem x)
{
return x.CriticRating ?? 0;
}
/// <summary>

View File

@@ -14,7 +14,12 @@ namespace MediaBrowser.Server.Implementations.Sorting
/// <returns>System.Int32.</returns>
public int Compare(BaseItem x, BaseItem y)
{
return (x.Revenue ?? 0).CompareTo(y.Revenue ?? 0);
return GetValue(x).CompareTo(GetValue(y));
}
private double GetValue(BaseItem x)
{
return x.Revenue ?? 0;
}
/// <summary>