reduced list enumerations
This commit is contained in:
parent
b1b4e77178
commit
5225e054cd
|
@ -82,9 +82,9 @@ namespace MediaBrowser.Api
|
|||
.SelectMany(i => new[] { i.AlbumArtist, i.Artist })
|
||||
.Where(i => !string.IsNullOrEmpty(i))
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
return points + artists1.Where(i => artists2.Contains(i, StringComparer.OrdinalIgnoreCase)).Sum(i => 5);
|
||||
return points + artists1.Where(artists2.ContainsKey).Sum(i => 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -156,10 +156,10 @@ namespace MediaBrowser.Api
|
|||
}
|
||||
|
||||
// Find common genres
|
||||
points += item1.Genres.Where(i => item2.Genres.Contains(i, StringComparer.OrdinalIgnoreCase)).Sum(i => 5);
|
||||
points += item1.Genres.Where(i => item2.Genres.Contains(i, StringComparer.OrdinalIgnoreCase)).Sum(i => 10);
|
||||
|
||||
// Find common tags
|
||||
points += item1.Tags.Where(i => item2.Tags.Contains(i, StringComparer.OrdinalIgnoreCase)).Sum(i => 5);
|
||||
points += item1.Tags.Where(i => item2.Tags.Contains(i, StringComparer.OrdinalIgnoreCase)).Sum(i => 10);
|
||||
|
||||
// Find common studios
|
||||
points += item1.Studios.Where(i => item2.Studios.Contains(i, StringComparer.OrdinalIgnoreCase)).Sum(i => 3);
|
||||
|
@ -168,23 +168,23 @@ namespace MediaBrowser.Api
|
|||
|
||||
points += item1.People.Where(i => item2PeopleNames.Contains(i.Name, StringComparer.OrdinalIgnoreCase)).Sum(i =>
|
||||
{
|
||||
if (string.Equals(i.Type, PersonType.Director, StringComparison.OrdinalIgnoreCase))
|
||||
if (string.Equals(i.Type, PersonType.Director, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Role, PersonType.Director, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
if (string.Equals(i.Type, PersonType.Actor, StringComparison.OrdinalIgnoreCase))
|
||||
if (string.Equals(i.Type, PersonType.Actor, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Role, PersonType.Actor, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
if (string.Equals(i.Type, PersonType.Composer, StringComparison.OrdinalIgnoreCase))
|
||||
if (string.Equals(i.Type, PersonType.Composer, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Role, PersonType.Composer, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
if (string.Equals(i.Type, PersonType.GuestStar, StringComparison.OrdinalIgnoreCase))
|
||||
if (string.Equals(i.Type, PersonType.GuestStar, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Role, PersonType.GuestStar, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
if (string.Equals(i.Type, PersonType.Writer, StringComparison.OrdinalIgnoreCase))
|
||||
if (string.Equals(i.Type, PersonType.Writer, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Role, PersonType.Writer, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
|
|
@ -157,7 +157,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
{
|
||||
var name = DeSlugGenreName(request.Name, LibraryManager);
|
||||
|
||||
var items = GetItems(request.UserId).Where(i => i.Genres != null && i.Genres.Contains(name, StringComparer.OrdinalIgnoreCase)).ToList();
|
||||
var items = GetItems(request.UserId).Where(i => i.Genres.Contains(name, StringComparer.OrdinalIgnoreCase)).ToList();
|
||||
|
||||
var counts = new ItemByNameCounts
|
||||
{
|
||||
|
|
|
@ -629,7 +629,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
items = items.Where(item =>
|
||||
item.People != null &&
|
||||
item.People.Any(p =>
|
||||
p.Name.Equals(personName, StringComparison.OrdinalIgnoreCase) && types.Contains(p.Type, StringComparer.OrdinalIgnoreCase)));
|
||||
p.Name.Equals(personName, StringComparison.OrdinalIgnoreCase) && (types.Contains(p.Type, StringComparer.OrdinalIgnoreCase) || types.Contains(p.Role, StringComparer.OrdinalIgnoreCase))));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -203,7 +203,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
return itemsList.Where(i => i.People.Any(p => p.Name.Equals(name, StringComparison.OrdinalIgnoreCase)));
|
||||
}
|
||||
|
||||
return itemsList.Where(i => i.People.Any(p => p.Name.Equals(name, StringComparison.OrdinalIgnoreCase) && personTypes.Contains(p.Type ?? string.Empty, StringComparer.OrdinalIgnoreCase)));
|
||||
return itemsList.Where(i => i.People.Any(p => p.Name.Equals(name, StringComparison.OrdinalIgnoreCase) && (personTypes.Contains(p.Type ?? string.Empty, StringComparer.OrdinalIgnoreCase) || personTypes.Contains(p.Role ?? string.Empty, StringComparer.OrdinalIgnoreCase))));
|
||||
}, GetEntity)
|
||||
);
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
|
||||
people :
|
||||
|
||||
people.Where(p => personTypes.Contains(p.Type ?? string.Empty, StringComparer.OrdinalIgnoreCase));
|
||||
people.Where(p => personTypes.Contains(p.Type ?? string.Empty, StringComparer.OrdinalIgnoreCase) || personTypes.Contains(p.Role ?? string.Empty, StringComparer.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using MediaBrowser.Common.Extensions;
|
||||
|
@ -361,19 +362,20 @@ namespace MediaBrowser.Controller.Providers
|
|||
|
||||
var sb = new StringBuilder();
|
||||
|
||||
var extensions = FilestampExtensions;
|
||||
var extensionsList = FilestampExtensions;
|
||||
var extensions = extensionsList.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
// Record the name of each file
|
||||
// Need to sort these because accoring to msdn docs, our i/o methods are not guaranteed in any order
|
||||
foreach (var file in resolveArgs.FileSystemChildren
|
||||
.Where(i => IncludeInFileStamp(i, extensions))
|
||||
.Where(i => IncludeInFileStamp(i, extensions, extensionsList.Length))
|
||||
.OrderBy(f => f.Name))
|
||||
{
|
||||
sb.Append(file.Name);
|
||||
}
|
||||
|
||||
foreach (var file in resolveArgs.MetadataFiles
|
||||
.Where(i => IncludeInFileStamp(i, extensions))
|
||||
.Where(i => IncludeInFileStamp(i, extensions, extensionsList.Length))
|
||||
.OrderBy(f => f.Name))
|
||||
{
|
||||
sb.Append(file.Name);
|
||||
|
@ -387,8 +389,9 @@ namespace MediaBrowser.Controller.Providers
|
|||
/// </summary>
|
||||
/// <param name="file">The file.</param>
|
||||
/// <param name="extensions">The extensions.</param>
|
||||
/// <param name="numExtensions">The num extensions.</param>
|
||||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
||||
private bool IncludeInFileStamp(FileSystemInfo file, string[] extensions)
|
||||
private bool IncludeInFileStamp(FileSystemInfo file, Dictionary<string,string> extensions, int numExtensions)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -397,7 +400,7 @@ namespace MediaBrowser.Controller.Providers
|
|||
return false;
|
||||
}
|
||||
|
||||
return extensions.Length == 0 || extensions.Contains(file.Extension, StringComparer.OrdinalIgnoreCase);
|
||||
return numExtensions == 0 || extensions.ContainsKey(file.Extension);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
|
|
|
@ -139,7 +139,7 @@ namespace MediaBrowser.Providers.MediaInfo
|
|||
stream.Language = GetDictionaryValue(streamInfo.tags, "language");
|
||||
}
|
||||
|
||||
if (streamInfo.codec_type.Equals("audio", StringComparison.OrdinalIgnoreCase))
|
||||
if (string.Equals(streamInfo.codec_type, "audio", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
stream.Type = MediaStreamType.Audio;
|
||||
|
||||
|
@ -150,11 +150,11 @@ namespace MediaBrowser.Providers.MediaInfo
|
|||
stream.SampleRate = int.Parse(streamInfo.sample_rate, UsCulture);
|
||||
}
|
||||
}
|
||||
else if (streamInfo.codec_type.Equals("subtitle", StringComparison.OrdinalIgnoreCase))
|
||||
else if (string.Equals(streamInfo.codec_type, "subtitle", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
stream.Type = MediaStreamType.Subtitle;
|
||||
}
|
||||
else if (streamInfo.codec_type.Equals("video", StringComparison.OrdinalIgnoreCase))
|
||||
else if (string.Equals(streamInfo.codec_type, "video", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
stream.Type = MediaStreamType.Video;
|
||||
|
||||
|
|
|
@ -115,7 +115,9 @@ namespace MediaBrowser.Providers.Movies
|
|||
|
||||
var updates = _jsonSerializer.DeserializeFromString<List<FanArtUpdatesPrescanTask.FanArtUpdate>>(json);
|
||||
|
||||
return updates.Select(i => i.id).Where(i => existingIds.Contains(i, StringComparer.OrdinalIgnoreCase));
|
||||
var existingDictionary = existingIds.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
return updates.Select(i => i.id).Where(existingDictionary.ContainsKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,6 +55,15 @@ namespace MediaBrowser.Providers.Music
|
|||
Current = this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the priority.
|
||||
/// </summary>
|
||||
/// <value>The priority.</value>
|
||||
public override MetadataProviderPriority Priority
|
||||
{
|
||||
get { return MetadataProviderPriority.Fourth; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Supportses the specified item.
|
||||
/// </summary>
|
||||
|
|
|
@ -119,9 +119,11 @@ namespace MediaBrowser.Providers.Music
|
|||
return new List<string>();
|
||||
}
|
||||
|
||||
var existingDictionary = existingArtistIds.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
var updates = _jsonSerializer.DeserializeFromString<List<FanArtUpdate>>(json);
|
||||
|
||||
return updates.Select(i => i.id).Where(i => existingArtistIds.Contains(i, StringComparer.OrdinalIgnoreCase));
|
||||
return updates.Select(i => i.id).Where(existingDictionary.ContainsKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,15 @@ namespace MediaBrowser.Providers.Music
|
|||
return BlankId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the priority.
|
||||
/// </summary>
|
||||
/// <value>The priority.</value>
|
||||
public override MetadataProviderPriority Priority
|
||||
{
|
||||
get { return MetadataProviderPriority.Third; }
|
||||
}
|
||||
|
||||
private bool HasAltMeta(BaseItem item)
|
||||
{
|
||||
return item.LocationType == LocationType.FileSystem && item.ResolveArgs.ContainsMetaFileByName("album.xml");
|
||||
|
|
|
@ -120,9 +120,11 @@ namespace MediaBrowser.Providers.TV
|
|||
return new List<string>();
|
||||
}
|
||||
|
||||
var existingDictionary = existingSeriesIds.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
var updates = _jsonSerializer.DeserializeFromString<List<FanArtUpdatesPrescanTask.FanArtUpdate>>(json);
|
||||
|
||||
return updates.Select(i => i.id).Where(i => existingSeriesIds.Contains(i, StringComparer.OrdinalIgnoreCase));
|
||||
return updates.Select(i => i.id).Where(existingDictionary.ContainsKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -151,10 +151,12 @@ namespace MediaBrowser.Providers.TV
|
|||
|
||||
var seriesNodes = doc.SelectNodes("//Series");
|
||||
|
||||
var existingDictionary = existingSeriesIds.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
var seriesList = seriesNodes == null ? new string[] { } :
|
||||
seriesNodes.Cast<XmlNode>()
|
||||
.Select(i => i.InnerText)
|
||||
.Where(i => !string.IsNullOrWhiteSpace(i) && existingSeriesIds.Contains(i, StringComparer.OrdinalIgnoreCase));
|
||||
.Where(i => !string.IsNullOrWhiteSpace(i) && existingDictionary.ContainsKey(i));
|
||||
|
||||
return new Tuple<IEnumerable<string>, string>(seriesList, newUpdateTime);
|
||||
}
|
||||
|
|
|
@ -846,11 +846,12 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
|
||||
var tasks = new List<Task>();
|
||||
|
||||
var includedPersonTypes = new[] { PersonType.Actor, PersonType.Director, PersonType.GuestStar, PersonType.Writer, PersonType.Director, PersonType.Producer };
|
||||
var includedPersonTypes = new[] { PersonType.Actor, PersonType.Director, PersonType.GuestStar, PersonType.Writer, PersonType.Director, PersonType.Producer }
|
||||
.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
var people = RootFolder.RecursiveChildren
|
||||
.Where(c => c.People != null)
|
||||
.SelectMany(c => c.People.Where(p => includedPersonTypes.Contains(p.Type, StringComparer.OrdinalIgnoreCase) || includedPersonTypes.Contains(p.Role, StringComparer.OrdinalIgnoreCase)))
|
||||
.SelectMany(c => c.People.Where(p => includedPersonTypes.ContainsKey(p.Type ?? string.Empty) || includedPersonTypes.ContainsKey(p.Role ?? string.Empty)))
|
||||
.DistinctBy(p => p.Name, StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user