Merge pull request #1719 from MediaBrowser/dev

Dev
This commit is contained in:
Luke 2016-05-09 11:49:33 -04:00
commit c478085902
8 changed files with 85 additions and 37 deletions

View File

@ -1293,33 +1293,41 @@ namespace MediaBrowser.Controller.Entities
public IList<BaseItem> GetRecursiveChildren(Func<BaseItem, bool> filter) public IList<BaseItem> GetRecursiveChildren(Func<BaseItem, bool> filter)
{ {
var list = new List<BaseItem>(); var result = new Dictionary<Guid, BaseItem>();
AddChildrenToList(list, true, filter); AddChildrenToList(result, true, true, filter);
return list; return result.Values.ToList();
} }
/// <summary> /// <summary>
/// Adds the children to list. /// Adds the children to list.
/// </summary> /// </summary>
/// <param name="list">The list.</param> private void AddChildrenToList(Dictionary<Guid,BaseItem> result, bool includeLinkedChildren, bool recursive, Func<BaseItem, bool> filter)
/// <param name="recursive">if set to <c>true</c> [recursive].</param>
/// <param name="filter">The filter.</param>
private void AddChildrenToList(List<BaseItem> list, bool recursive, Func<BaseItem, bool> filter)
{ {
foreach (var child in Children) foreach (var child in Children)
{ {
if (filter == null || filter(child)) if (filter == null || filter(child))
{ {
list.Add(child); result[child.Id] = child;
} }
if (recursive && child.IsFolder) if (recursive && child.IsFolder)
{ {
var folder = (Folder)child; var folder = (Folder)child;
folder.AddChildrenToList(list, true, filter); folder.AddChildrenToList(result, includeLinkedChildren, true, filter);
}
}
if (includeLinkedChildren)
{
foreach (var child in GetLinkedChildren())
{
if (filter == null || filter(child))
{
result[child.Id] = child;
}
} }
} }
} }

View File

@ -421,7 +421,8 @@ namespace MediaBrowser.Providers.Manager
var folder = item as Folder; var folder = item as Folder;
if (folder != null && folder.SupportsCumulativeRunTimeTicks) if (folder != null && folder.SupportsCumulativeRunTimeTicks)
{ {
var ticks = folder.GetRecursiveChildren(i => !i.IsFolder).Select(i => i.RunTimeTicks ?? 0).Sum(); var items = folder.GetRecursiveChildren(i => !i.IsFolder).ToList();
var ticks = items.Select(i => i.RunTimeTicks ?? 0).Sum();
if (!folder.RunTimeTicks.HasValue || folder.RunTimeTicks.Value != ticks) if (!folder.RunTimeTicks.HasValue || folder.RunTimeTicks.Value != ticks)
{ {
@ -443,9 +444,10 @@ namespace MediaBrowser.Providers.Manager
var folder = item as Folder; var folder = item as Folder;
if (folder != null && folder.SupportsDateLastMediaAdded) if (folder != null && folder.SupportsDateLastMediaAdded)
{ {
var date = folder.GetRecursiveChildren(i => !i.IsFolder).Select(i => i.DateCreated).Max(); var items = folder.GetRecursiveChildren(i => !i.IsFolder).Select(i => i.DateCreated).ToList();
var date = items.Count == 0 ? (DateTime?)null : items.Max();
if (!folder.DateLastMediaAdded.HasValue || folder.DateLastMediaAdded.Value != date) if ((!folder.DateLastMediaAdded.HasValue && date.HasValue) || folder.DateLastMediaAdded != date)
{ {
folder.DateLastMediaAdded = date; folder.DateLastMediaAdded = date;
updateType = ItemUpdateType.MetadataEdit; updateType = ItemUpdateType.MetadataEdit;

View File

@ -176,8 +176,12 @@ namespace MediaBrowser.Providers.Movies
var numComplete = 0; var numComplete = 0;
// Gather all movies into a lookup by tmdb id // Gather all movies into a lookup by tmdb id
var allMovies = _libraryManager.RootFolder var allMovies = _libraryManager.GetItemList(new Controller.Entities.InternalItemsQuery
.GetRecursiveChildren(i => i is Movie && !string.IsNullOrEmpty(i.GetProviderId(MetadataProviders.Tmdb))) {
IncludeItemTypes = new[] {typeof (Movie).Name},
Recursive = true
}).Where(i => !string.IsNullOrEmpty(i.GetProviderId(MetadataProviders.Tmdb)))
.ToLookup(i => i.GetProviderId(MetadataProviders.Tmdb)); .ToLookup(i => i.GetProviderId(MetadataProviders.Tmdb));
foreach (var id in list) foreach (var id in list)

View File

@ -536,7 +536,11 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
result.ExtractedName = nameWithoutYear; result.ExtractedName = nameWithoutYear;
result.ExtractedYear = yearInName; result.ExtractedYear = yearInName;
var series = _libraryManager.RootFolder.GetRecursiveChildren(i => i is Series) var series = _libraryManager.GetItemList(new Controller.Entities.InternalItemsQuery
{
IncludeItemTypes = new[] { typeof(Series).Name },
Recursive = true
})
.Cast<Series>() .Cast<Series>()
.Select(i => NameUtils.GetMatchScore(nameWithoutYear, yearInName, i)) .Select(i => NameUtils.GetMatchScore(nameWithoutYear, yearInName, i))
.Where(i => i.Item2 > 0) .Where(i => i.Item2 > 0)
@ -550,9 +554,11 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
if (info != null) if (info != null)
{ {
series = _libraryManager.RootFolder series = _libraryManager.GetItemList(new Controller.Entities.InternalItemsQuery
.GetRecursiveChildren(i => i is Series) {
.Cast<Series>() IncludeItemTypes = new[] { typeof(Series).Name },
Recursive = true
}).Cast<Series>()
.FirstOrDefault(i => string.Equals(i.Name, info.ItemName, StringComparison.OrdinalIgnoreCase)); .FirstOrDefault(i => string.Equals(i.Name, info.ItemName, StringComparison.OrdinalIgnoreCase));
} }
} }

View File

@ -22,7 +22,7 @@ namespace MediaBrowser.Server.Implementations.Library
{ {
public event EventHandler<UserDataSaveEventArgs> UserDataSaved; public event EventHandler<UserDataSaveEventArgs> UserDataSaved;
private readonly ConcurrentDictionary<string, UserItemData> _userData = new ConcurrentDictionary<string, UserItemData>(); private readonly Dictionary<string, UserItemData> _userData = new Dictionary<string, UserItemData>(StringComparer.OrdinalIgnoreCase);
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IServerConfigurationManager _config; private readonly IServerConfigurationManager _config;
@ -66,8 +66,10 @@ namespace MediaBrowser.Server.Implementations.Library
var newValue = userData; var newValue = userData;
// Once it succeeds, put it into the dictionary to make it available to everyone else lock (_userData)
_userData.AddOrUpdate(GetCacheKey(userId, key), newValue, delegate { return newValue; }); {
_userData[GetCacheKey(userId, key)] = newValue;
}
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -154,13 +156,33 @@ namespace MediaBrowser.Server.Implementations.Library
throw new ArgumentNullException("key"); throw new ArgumentNullException("key");
} }
return _userData.GetOrAdd(GetCacheKey(userId, key), keyName => GetUserDataFromRepository(userId, key)); lock (_userData)
{
var cacheKey = GetCacheKey(userId, key);
UserItemData value;
if (_userData.TryGetValue(cacheKey, out value))
{
return value;
}
value = GetUserDataFromRepository(userId, key);
_userData[cacheKey] = value;
return value;
}
} }
private UserItemData GetUserDataFromRepository(Guid userId, string key) private UserItemData GetUserDataFromRepository(Guid userId, string key)
{ {
var data = Repository.GetUserData(userId, key); var data = Repository.GetUserData(userId, key);
if (data == null)
{
data = new UserItemData
{
UserId = userId,
Key = key
};
}
return data; return data;
} }

View File

@ -2056,6 +2056,10 @@ namespace MediaBrowser.Server.Implementations.Persistence
{ {
var whereClauses = new List<string>(); var whereClauses = new List<string>();
if (EnableJoinUserData(query))
{
whereClauses.Add("UserId=@UserId");
}
if (query.IsCurrentSchema.HasValue) if (query.IsCurrentSchema.HasValue)
{ {
if (query.IsCurrentSchema.Value) if (query.IsCurrentSchema.Value)

View File

@ -296,11 +296,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
} }
} }
return new UserItemData return null;
{
UserId = userId,
Key = key
};
} }
} }

View File

@ -12,6 +12,7 @@ using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using CommonIO; using CommonIO;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Server.Implementations.ScheduledTasks namespace MediaBrowser.Server.Implementations.ScheduledTasks
{ {
@ -85,8 +86,13 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks
/// <returns>Task.</returns> /// <returns>Task.</returns>
public async Task Execute(CancellationToken cancellationToken, IProgress<double> progress) public async Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
{ {
var videos = _libraryManager.RootFolder.GetRecursiveChildren(i => i is Video) var videos = _libraryManager.GetItemList(new InternalItemsQuery
.Cast<Video>() {
MediaTypes = new[] { MediaType.Video },
IsFolder = false,
Recursive = true
})
.OfType<Video>()
.ToList(); .ToList();
var numComplete = 0; var numComplete = 0;