fix episode query

This commit is contained in:
Luke Pulverenti 2016-05-06 22:11:22 -04:00
parent c431625d39
commit d04b39421e
5 changed files with 54 additions and 52 deletions

View File

@ -199,8 +199,8 @@ namespace MediaBrowser.Controller.Entities
/// <returns>Dictionary{System.StringFunc{UserIEnumerable{BaseItem}}}.</returns> /// <returns>Dictionary{System.StringFunc{UserIEnumerable{BaseItem}}}.</returns>
protected virtual IEnumerable<string> GetIndexByOptions() protected virtual IEnumerable<string> GetIndexByOptions()
{ {
return new List<string> { return new List<string> {
{"None"}, {"None"},
{"Performer"}, {"Performer"},
{"Genre"}, {"Genre"},
{"Director"}, {"Director"},
@ -1569,7 +1569,15 @@ namespace MediaBrowser.Controller.Entities
public override bool IsPlayed(User user) public override bool IsPlayed(User user)
{ {
return GetRecursiveChildren(user, i => !i.IsFolder && i.LocationType != LocationType.Virtual) var itemsResult = GetItems(new InternalItemsQuery(user)
{
Recursive = true,
IsFolder = false,
ExcludeLocationTypes = new[] { LocationType.Virtual }
}).Result;
return itemsResult.Items
.All(i => i.IsPlayed(user)); .All(i => i.IsPlayed(user));
} }
@ -1613,19 +1621,15 @@ namespace MediaBrowser.Controller.Entities
double totalPercentPlayed = 0; double totalPercentPlayed = 0;
IEnumerable<BaseItem> children; var itemsResult = GetItems(new InternalItemsQuery(user)
var folder = this;
var season = folder as Season;
if (season != null)
{ {
children = season.GetEpisodes(user).Where(i => i.LocationType != LocationType.Virtual); Recursive = true,
} IsFolder = false,
else ExcludeLocationTypes = new[] { LocationType.Virtual }
{
children = folder.GetRecursiveChildren(user, i => !i.IsFolder && i.LocationType != LocationType.Virtual); }).Result;
}
var children = itemsResult.Items;
// Loop through each recursive child // Loop through each recursive child
foreach (var child in children) foreach (var child in children)

View File

@ -156,24 +156,16 @@ namespace MediaBrowser.Controller.Entities.TV
protected override Task<QueryResult<BaseItem>> GetItemsInternal(InternalItemsQuery query) protected override Task<QueryResult<BaseItem>> GetItemsInternal(InternalItemsQuery query)
{ {
if (query.User == null)
{
return base.GetItemsInternal(query);
}
var user = query.User; var user = query.User;
Func<BaseItem, bool> filter = i => UserViewBuilder.Filter(i, user, query, UserDataManager, LibraryManager); Func<BaseItem, bool> filter = i => UserViewBuilder.Filter(i, user, query, UserDataManager, LibraryManager);
IEnumerable<BaseItem> items; var items = GetEpisodes(user).Where(filter);
if (query.User == null)
{
items = query.Recursive
? GetRecursiveChildren(filter)
: Children.Where(filter);
}
else
{
items = query.Recursive
? GetRecursiveChildren(user, filter)
: GetChildren(user, true).Where(filter);
}
var result = PostFilterAndSort(items, query); var result = PostFilterAndSort(items, query);
@ -269,11 +261,6 @@ namespace MediaBrowser.Controller.Entities.TV
return GetEpisodes(user); return GetEpisodes(user);
} }
public override IEnumerable<BaseItem> GetRecursiveChildren(User user, Func<BaseItem, bool> filter)
{
return GetEpisodes(user).Where(filter);
}
protected override bool GetBlockUnratedValue(UserPolicy config) protected override bool GetBlockUnratedValue(UserPolicy config)
{ {
// Don't block. Let either the entire series rating or episode rating determine it // Don't block. Let either the entire series rating or episode rating determine it

View File

@ -6,6 +6,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using System.Threading.Tasks;
namespace MediaBrowser.Controller.Playlists namespace MediaBrowser.Controller.Playlists
{ {
@ -50,12 +51,12 @@ namespace MediaBrowser.Controller.Playlists
public override IEnumerable<BaseItem> GetChildren(User user, bool includeLinkedChildren) public override IEnumerable<BaseItem> GetChildren(User user, bool includeLinkedChildren)
{ {
return GetPlayableItems(user); return GetPlayableItems(user).Result;
} }
public override IEnumerable<BaseItem> GetRecursiveChildren(User user, Func<BaseItem, bool> filter) public override IEnumerable<BaseItem> GetRecursiveChildren(User user, Func<BaseItem, bool> filter)
{ {
var items = GetPlayableItems(user); var items = GetPlayableItems(user).Result;
if (filter != null) if (filter != null)
{ {
@ -70,23 +71,30 @@ namespace MediaBrowser.Controller.Playlists
return GetLinkedChildrenInfos(); return GetLinkedChildrenInfos();
} }
private IEnumerable<BaseItem> GetPlayableItems(User user) private Task<IEnumerable<BaseItem>> GetPlayableItems(User user)
{ {
return GetPlaylistItems(MediaType, base.GetChildren(user, true), user); return GetPlaylistItems(MediaType, base.GetChildren(user, true), user);
} }
public static IEnumerable<BaseItem> GetPlaylistItems(string playlistMediaType, IEnumerable<BaseItem> inputItems, User user) public static async Task<IEnumerable<BaseItem>> GetPlaylistItems(string playlistMediaType, IEnumerable<BaseItem> inputItems, User user)
{ {
if (user != null) if (user != null)
{ {
inputItems = inputItems.Where(i => i.IsVisible(user)); inputItems = inputItems.Where(i => i.IsVisible(user));
} }
return inputItems.SelectMany(i => GetPlaylistItems(i, user)) var list = new List<BaseItem>();
.Where(m => string.Equals(m.MediaType, playlistMediaType, StringComparison.OrdinalIgnoreCase));
foreach (var item in inputItems)
{
var playlistItems = await GetPlaylistItems(item, user, playlistMediaType).ConfigureAwait(false);
list.AddRange(playlistItems);
}
return list;
} }
private static IEnumerable<BaseItem> GetPlaylistItems(BaseItem item, User user) private static async Task<IEnumerable<BaseItem>> GetPlaylistItems(BaseItem item, User user, string mediaType)
{ {
var musicGenre = item as MusicGenre; var musicGenre = item as MusicGenre;
if (musicGenre != null) if (musicGenre != null)
@ -119,15 +127,18 @@ namespace MediaBrowser.Controller.Playlists
var folder = item as Folder; var folder = item as Folder;
if (folder != null) if (folder != null)
{ {
var items = user == null var query = new InternalItemsQuery(user)
? folder.GetRecursiveChildren(m => !m.IsFolder)
: folder.GetRecursiveChildren(user, m => !m.IsFolder);
if (folder.IsPreSorted)
{ {
return items; Recursive = true,
} IsFolder = false,
return LibraryManager.Sort(items, user, new[] { ItemSortBy.SortName }, SortOrder.Ascending); SortBy = new[] { ItemSortBy.SortName },
MediaTypes = new[] { mediaType }
};
var itemsResult = await folder.GetItems(query).ConfigureAwait(false);
var items = itemsResult.Items;
return items;
} }
return new[] { item }; return new[] { item };

View File

@ -82,7 +82,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
private IDbCommand _updateInheritedRatingCommand; private IDbCommand _updateInheritedRatingCommand;
private IDbCommand _updateInheritedTagsCommand; private IDbCommand _updateInheritedTagsCommand;
public const int LatestSchemaVersion = 71; public const int LatestSchemaVersion = 72;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="SqliteItemRepository"/> class. /// Initializes a new instance of the <see cref="SqliteItemRepository"/> class.

View File

@ -158,7 +158,7 @@ namespace MediaBrowser.Server.Implementations.Playlists
return path; return path;
} }
private IEnumerable<BaseItem> GetPlaylistItems(IEnumerable<string> itemIds, string playlistMediaType, User user) private Task<IEnumerable<BaseItem>> GetPlaylistItems(IEnumerable<string> itemIds, string playlistMediaType, User user)
{ {
var items = itemIds.Select(i => _libraryManager.GetItemById(i)).Where(i => i != null); var items = itemIds.Select(i => _libraryManager.GetItemById(i)).Where(i => i != null);
@ -183,7 +183,7 @@ namespace MediaBrowser.Server.Implementations.Playlists
var list = new List<LinkedChild>(); var list = new List<LinkedChild>();
var items = GetPlaylistItems(itemIds, playlist.MediaType, user) var items = (await GetPlaylistItems(itemIds, playlist.MediaType, user).ConfigureAwait(false))
.Where(i => i.SupportsAddingToPlaylist) .Where(i => i.SupportsAddingToPlaylist)
.ToList(); .ToList();