update views

This commit is contained in:
Luke Pulverenti 2015-11-18 00:49:20 -05:00
parent 736d87fd7e
commit 904175ce26
14 changed files with 96 additions and 193 deletions

View File

@ -70,9 +70,7 @@ namespace MediaBrowser.Api
_config.Configuration.EnableStandaloneMetadata = true;
_config.Configuration.EnableLibraryMetadataSubFolder = true;
_config.Configuration.EnableCustomPathSubFolders = true;
_config.Configuration.EnableUserViews = true;
_config.Configuration.EnableDateLastRefresh = true;
_config.Configuration.EnableSharedCollectionViewImage = true;
_config.SaveConfiguration();
}

View File

@ -140,7 +140,7 @@ namespace MediaBrowser.Api.UserLibrary
var views = user.RootFolder
.GetChildren(user, true)
.OfType<Folder>()
.Where(i => !UserView.IsExcludedFromGrouping(i))
.Where(UserView.IsEligibleForGrouping)
.ToList();
var list = views

View File

@ -20,7 +20,6 @@ namespace MediaBrowser.Controller.Entities
{
public static IUserManager UserManager { get; set; }
public static IXmlSerializer XmlSerializer { get; set; }
public bool EnableUserViews { get; set; }
/// <summary>
/// From now on all user paths will be Id-based.

View File

@ -101,30 +101,6 @@ namespace MediaBrowser.Controller.Entities
return GetChildren(user, false);
}
public static bool IsExcludedFromGrouping(Folder folder)
{
var standaloneTypes = new List<string>
{
CollectionType.Books,
CollectionType.HomeVideos,
CollectionType.Photos,
CollectionType.Playlists,
CollectionType.BoxSets,
CollectionType.MusicVideos,
CollectionType.Games,
CollectionType.Music
};
var collectionFolder = folder as ICollectionFolder;
if (collectionFolder == null)
{
return false;
}
return standaloneTypes.Contains(collectionFolder.CollectionType ?? string.Empty);
}
public static bool IsUserSpecific(Folder folder)
{
var standaloneTypes = new List<string>
@ -148,6 +124,24 @@ namespace MediaBrowser.Controller.Entities
return standaloneTypes.Contains(collectionFolder.CollectionType ?? string.Empty);
}
public static bool IsEligibleForGrouping(Folder folder)
{
var collectionFolder = folder as ICollectionFolder;
return collectionFolder != null && IsEligibleForGrouping(collectionFolder.CollectionType);
}
public static bool IsEligibleForGrouping(string viewType)
{
var types = new[]
{
CollectionType.Movies,
CollectionType.TvShows,
string.Empty
};
return types.Contains(viewType ?? string.Empty, StringComparer.OrdinalIgnoreCase);
}
public static bool IsEligibleForEnhancedView(string viewType)
{
var types = new[]

View File

@ -1712,12 +1712,12 @@ namespace MediaBrowser.Controller.Entities
return _libraryManager.RootFolder
.Children
.OfType<Folder>()
.Where(i => !UserView.IsExcludedFromGrouping(i));
.Where(UserView.IsEligibleForGrouping);
}
return user.RootFolder
.GetChildren(user, true)
.OfType<Folder>()
.Where(i => user.IsFolderGrouped(i.Id) && !UserView.IsExcludedFromGrouping(i));
.Where(i => user.IsFolderGrouped(i.Id) && UserView.IsEligibleForGrouping(i));
}
private IEnumerable<Folder> GetMediaFolders(User user, IEnumerable<string> viewTypes)

View File

@ -337,7 +337,6 @@ namespace MediaBrowser.Controller.Library
string parentId,
string viewType,
string sortName,
string uniqueId,
CancellationToken cancellationToken);
/// <summary>
@ -391,13 +390,11 @@ namespace MediaBrowser.Controller.Library
/// <param name="parent">The parent.</param>
/// <param name="viewType">Type of the view.</param>
/// <param name="sortName">Name of the sort.</param>
/// <param name="uniqueId">The unique identifier.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task&lt;UserView&gt;.</returns>
Task<UserView> GetShadowView(BaseItem parent,
string viewType,
string sortName,
string uniqueId,
CancellationToken cancellationToken);
/// <summary>

View File

@ -98,12 +98,6 @@ namespace MediaBrowser.Model.Configuration
/// <value><c>true</c> if [enable localized guids]; otherwise, <c>false</c>.</value>
public bool EnableLocalizedGuids { get; set; }
/// <summary>
/// Gets or sets a value indicating whether [enable user views].
/// </summary>
/// <value><c>true</c> if [enable user views]; otherwise, <c>false</c>.</value>
public bool EnableUserViews { get; set; }
/// <summary>
/// Gets or sets a value indicating whether [enable library metadata sub folder].
/// </summary>
@ -229,7 +223,6 @@ namespace MediaBrowser.Model.Configuration
public int MigrationVersion { get; set; }
public bool EnableImagePreDownloading { get; set; }
public bool EnableSharedCollectionViewImage { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="ServerConfiguration" /> class.

View File

@ -1320,7 +1320,7 @@ namespace MediaBrowser.Server.Implementations.Library
{
var parents = parentIds.Select(i => GetItemById(new Guid(i))).ToList();
query.TopParentIds = parents.SelectMany(GetTopParentsForQuery).Select(i => i.Id.ToString("N")).ToArray();
SetTopParentIdsOrAncestors(query, parents);
return GetItemIds(query).Select(GetItemById);
}
@ -1329,11 +1329,35 @@ namespace MediaBrowser.Server.Implementations.Library
{
var parents = parentIds.Select(i => GetItemById(new Guid(i))).ToList();
query.TopParentIds = parents.SelectMany(GetTopParentsForQuery).Select(i => i.Id.ToString("N")).ToArray();
SetTopParentIdsOrAncestors(query, parents);
return GetItems(query);
}
private void SetTopParentIdsOrAncestors(InternalItemsQuery query, List<BaseItem> parents)
{
if (parents.All(i =>
{
if ((i is ICollectionFolder) || (i is UserView))
{
return true;
}
_logger.Debug("Query requires ancestor query due to type: " + i.GetType().Name);
return false;
}))
{
// Optimize by querying against top level views
query.TopParentIds = parents.SelectMany(i => GetTopParentsForQuery(i, query.User)).Select(i => i.Id.ToString("N")).ToArray();
}
else
{
// We need to be able to query from any arbitrary ancestor up the tree
query.AncestorIds = parents.SelectMany(i => i.GetIdsForAncestorQuery()).Select(i => i.ToString("N")).ToArray();
}
}
private void AddUserToQuery(InternalItemsQuery query, User user)
{
if (query.AncestorIds.Length == 0 && !query.ParentId.HasValue && query.ChannelIds.Length == 0 && query.TopParentIds.Length == 0)
@ -1345,11 +1369,11 @@ namespace MediaBrowser.Server.Implementations.Library
}, CancellationToken.None).Result.ToList();
query.TopParentIds = userViews.SelectMany(GetTopParentsForQuery).Select(i => i.Id.ToString("N")).ToArray();
query.TopParentIds = userViews.SelectMany(i => GetTopParentsForQuery(i, user)).Select(i => i.Id.ToString("N")).ToArray();
}
}
private IEnumerable<BaseItem> GetTopParentsForQuery(BaseItem item)
private IEnumerable<BaseItem> GetTopParentsForQuery(BaseItem item, User user)
{
var view = item as UserView;
@ -1371,7 +1395,7 @@ namespace MediaBrowser.Server.Implementations.Library
var displayParent = GetItemById(view.DisplayParentId);
if (displayParent != null)
{
return GetTopParentsForQuery(displayParent);
return GetTopParentsForQuery(displayParent, user);
}
return new BaseItem[] { };
}
@ -1380,12 +1404,17 @@ namespace MediaBrowser.Server.Implementations.Library
var displayParent = GetItemById(view.ParentId);
if (displayParent != null)
{
return GetTopParentsForQuery(displayParent);
return GetTopParentsForQuery(displayParent, user);
}
return new BaseItem[] { };
}
// Handle grouping
if (user != null && !string.IsNullOrWhiteSpace(view.ViewType) && UserView.IsEligibleForGrouping(view.ViewType))
{
var collectionFolders = user.RootFolder.GetChildren(user, true).OfType<CollectionFolder>().Where(i => string.IsNullOrWhiteSpace(i.CollectionType) || string.Equals(i.CollectionType, view.ViewType, StringComparison.OrdinalIgnoreCase));
return collectionFolders.SelectMany(i => GetTopParentsForQuery(i, user));
}
return new BaseItem[] { };
}
@ -1797,7 +1826,7 @@ namespace MediaBrowser.Server.Implementations.Library
string sortName,
CancellationToken cancellationToken)
{
return GetNamedViewInternal(user, name, null, viewType, sortName, null, cancellationToken);
return GetNamedView(user, name, null, viewType, sortName, cancellationToken);
}
public async Task<UserView> GetNamedView(string name,
@ -1815,8 +1844,7 @@ namespace MediaBrowser.Server.Implementations.Library
var refresh = false;
if (item == null ||
!string.Equals(item.Path, path, StringComparison.OrdinalIgnoreCase))
if (item == null || !string.Equals(item.Path, path, StringComparison.OrdinalIgnoreCase))
{
_fileSystem.CreateDirectory(path);
@ -1835,11 +1863,6 @@ namespace MediaBrowser.Server.Implementations.Library
refresh = true;
}
if (!string.Equals(viewType, item.ViewType, StringComparison.OrdinalIgnoreCase))
{
refresh = true;
}
if (!refresh)
{
refresh = (DateTime.UtcNow - item.DateLastRefreshed) >= _viewRefreshInterval;
@ -1865,40 +1888,14 @@ namespace MediaBrowser.Server.Implementations.Library
return item;
}
public Task<UserView> GetNamedView(User user,
public async Task<UserView> GetNamedView(User user,
string name,
string parentId,
string viewType,
string sortName,
string uniqueId,
CancellationToken cancellationToken)
{
if (string.IsNullOrWhiteSpace(parentId))
{
throw new ArgumentNullException("parentId");
}
return GetNamedViewInternal(user, name, parentId, viewType, sortName, uniqueId, cancellationToken);
}
private async Task<UserView> GetNamedViewInternal(User user,
string name,
string parentId,
string viewType,
string sortName,
string uniqueId,
CancellationToken cancellationToken)
{
if (string.IsNullOrWhiteSpace(name))
{
throw new ArgumentNullException("name");
}
var idValues = "37_namedview_" + name + user.Id.ToString("N") + (parentId ?? string.Empty);
if (!string.IsNullOrWhiteSpace(uniqueId))
{
idValues += uniqueId;
}
var idValues = "38_namedview_" + name + user.Id.ToString("N") + (parentId ?? string.Empty) + (viewType ?? string.Empty);
var id = GetNewItemId(idValues, typeof(UserView));
@ -1933,13 +1930,6 @@ namespace MediaBrowser.Server.Implementations.Library
isNew = true;
}
if (!item.UserId.HasValue || !string.Equals(viewType, item.ViewType, StringComparison.OrdinalIgnoreCase))
{
item.UserId = user.Id;
item.ViewType = viewType;
await item.UpdateToRepository(ItemUpdateType.MetadataEdit, cancellationToken).ConfigureAwait(false);
}
var refresh = isNew || (DateTime.UtcNow - item.DateLastRefreshed) >= _viewRefreshInterval;
if (!refresh && item.DisplayParentId != Guid.Empty)
@ -1963,7 +1953,6 @@ namespace MediaBrowser.Server.Implementations.Library
public async Task<UserView> GetShadowView(BaseItem parent,
string viewType,
string sortName,
string uniqueId,
CancellationToken cancellationToken)
{
if (parent == null)
@ -1974,11 +1963,7 @@ namespace MediaBrowser.Server.Implementations.Library
var name = parent.Name;
var parentId = parent.Id;
var idValues = "37_namedview_" + name + parentId + (viewType ?? string.Empty);
if (!string.IsNullOrWhiteSpace(uniqueId))
{
idValues += uniqueId;
}
var idValues = "38_namedview_" + name + parentId + (viewType ?? string.Empty);
var id = GetNewItemId(idValues, typeof(UserView));
@ -2009,12 +1994,6 @@ namespace MediaBrowser.Server.Implementations.Library
isNew = true;
}
if (!string.Equals(viewType, item.ViewType, StringComparison.OrdinalIgnoreCase))
{
item.ViewType = viewType;
await item.UpdateToRepository(ItemUpdateType.MetadataEdit, cancellationToken).ConfigureAwait(false);
}
var refresh = isNew || (DateTime.UtcNow - item.DateLastRefreshed) >= _viewRefreshInterval;
if (!refresh && item.DisplayParentId != Guid.Empty)

View File

@ -707,8 +707,7 @@ namespace MediaBrowser.Server.Implementations.Library
Id = Guid.NewGuid(),
DateCreated = DateTime.UtcNow,
DateModified = DateTime.UtcNow,
UsesIdForConfigurationPath = true,
EnableUserViews = true
UsesIdForConfigurationPath = true
};
}

View File

@ -60,93 +60,52 @@ namespace MediaBrowser.Server.Implementations.Library
var plainFolderIds = user.Configuration.PlainFolderViews.Select(i => new Guid(i)).ToList();
var standaloneFolders = folders
.Where(i => UserView.IsExcludedFromGrouping(i) || !user.IsFolderGrouped(i.Id))
.ToList();
var foldersWithViewTypes = folders
.Except(standaloneFolders)
.OfType<ICollectionFolder>()
.ToList();
var groupedFolders = new List<ICollectionFolder>();
var list = new List<Folder>();
var enableUserViews = _config.Configuration.EnableUserViews || user.EnableUserViews;
foreach (var folder in standaloneFolders)
foreach (var folder in folders)
{
var collectionFolder = folder as ICollectionFolder;
var folderViewType = collectionFolder == null ? null : collectionFolder.CollectionType;
if (UserView.IsUserSpecific(folder))
{
list.Add(await GetUserView(folder.Id, folder.Name, folderViewType, true, string.Empty, user, cancellationToken).ConfigureAwait(false));
list.Add(await _libraryManager.GetNamedView(user, folder.Name, folder.Id.ToString("N"), folderViewType, null, cancellationToken).ConfigureAwait(false));
continue;
}
if (enableUserViews)
if (plainFolderIds.Contains(folder.Id) && UserView.IsEligibleForEnhancedView(folderViewType))
{
if (plainFolderIds.Contains(folder.Id) && UserView.IsEligibleForEnhancedView(folderViewType))
{
list.Add(await GetUserView(folder, folderViewType, false, string.Empty, cancellationToken).ConfigureAwait(false));
}
else if (query.PresetViews.Contains(folderViewType ?? string.Empty, StringComparer.OrdinalIgnoreCase))
{
list.Add(await GetUserView(folder, folderViewType, true, string.Empty, cancellationToken).ConfigureAwait(false));
}
else if (_config.Configuration.EnableSharedCollectionViewImage || UserView.EnableOriginalFolder(folderViewType))
{
list.Add(folder);
}
else if (!string.IsNullOrWhiteSpace(folderViewType))
{
list.Add(await GetUserView(folder, folderViewType, true, string.Empty, cancellationToken).ConfigureAwait(false));
}
else
{
list.Add(folder);
}
list.Add(folder);
continue;
}
if (collectionFolder != null && UserView.IsEligibleForGrouping(folder) && user.IsFolderGrouped(folder.Id))
{
groupedFolders.Add(collectionFolder);
continue;
}
if (query.PresetViews.Contains(folderViewType ?? string.Empty, StringComparer.OrdinalIgnoreCase))
{
list.Add(await GetUserView(folder, folderViewType, string.Empty, cancellationToken).ConfigureAwait(false));
}
else
{
// TODO: Deprecate this whole block
if (plainFolderIds.Contains(folder.Id) && UserView.IsEligibleForEnhancedView(folderViewType))
{
list.Add(await GetUserView(folder.Id, folder.Name, folderViewType, false, string.Empty, user, cancellationToken).ConfigureAwait(false));
}
else if (query.PresetViews.Contains(folderViewType ?? string.Empty, StringComparer.OrdinalIgnoreCase))
{
list.Add(await GetUserView(folder, folderViewType, true, string.Empty, cancellationToken).ConfigureAwait(false));
}
else if (_config.Configuration.EnableSharedCollectionViewImage || UserView.EnableOriginalFolder(folderViewType))
{
list.Add(folder);
}
else if (!string.IsNullOrWhiteSpace(folderViewType))
{
list.Add(await GetUserView(folder.Id, folder.Name, folderViewType, true, string.Empty, user, cancellationToken).ConfigureAwait(false));
}
else
{
list.Add(folder);
}
list.Add(folder);
}
}
var parents = foldersWithViewTypes.Where(i => string.Equals(i.GetViewType(user), CollectionType.TvShows, StringComparison.OrdinalIgnoreCase) || string.IsNullOrWhiteSpace(i.GetViewType(user)))
.ToList();
if (parents.Count > 0)
foreach (var viewType in new[] { CollectionType.Movies, CollectionType.TvShows })
{
list.Add(await GetUserView(parents, CollectionType.TvShows, string.Empty, user, query.PresetViews, cancellationToken).ConfigureAwait(false));
}
var parents = groupedFolders.Where(i => string.Equals(i.CollectionType, viewType, StringComparison.OrdinalIgnoreCase) || string.IsNullOrWhiteSpace(i.CollectionType))
.ToList();
parents = foldersWithViewTypes.Where(i => string.Equals(i.GetViewType(user), CollectionType.Movies, StringComparison.OrdinalIgnoreCase) || string.IsNullOrWhiteSpace(i.GetViewType(user)))
.ToList();
if (parents.Count > 0)
{
list.Add(await GetUserView(parents, CollectionType.Movies, string.Empty, user, query.PresetViews, cancellationToken).ConfigureAwait(false));
if (parents.Count > 0)
{
list.Add(await GetUserView(parents, viewType, string.Empty, user, query.PresetViews, cancellationToken).ConfigureAwait(false));
}
}
if (user.Configuration.DisplayFoldersView)
@ -225,35 +184,23 @@ namespace MediaBrowser.Server.Implementations.Library
private async Task<Folder> GetUserView(List<ICollectionFolder> parents, string viewType, string sortName, User user, string[] presetViews, CancellationToken cancellationToken)
{
if (parents.Count == 1 && parents.All(i => string.Equals(i.GetViewType(user), viewType, StringComparison.OrdinalIgnoreCase)))
if (parents.Count == 1 && parents.All(i => string.Equals(i.CollectionType, viewType, StringComparison.OrdinalIgnoreCase)))
{
if (!presetViews.Contains(viewType, StringComparer.OrdinalIgnoreCase))
{
return (Folder)parents[0];
}
var parentId = parents[0].Id;
var enableRichView = !user.Configuration.PlainFolderViews.Contains(parentId.ToString("N"), StringComparer.OrdinalIgnoreCase);
return await GetUserView((Folder)parents[0], viewType, enableRichView, string.Empty, cancellationToken).ConfigureAwait(false);
return await GetUserView((Folder)parents[0], viewType, string.Empty, cancellationToken).ConfigureAwait(false);
}
var name = _localizationManager.GetLocalizedString("ViewType" + viewType);
return await _libraryManager.GetNamedView(user, name, viewType, sortName, cancellationToken).ConfigureAwait(false);
}
public Task<UserView> GetUserView(Guid parentId, string name, string viewType, bool enableRichView, string sortName, User user, CancellationToken cancellationToken)
public Task<UserView> GetUserView(Folder parent, string viewType, string sortName, CancellationToken cancellationToken)
{
viewType = enableRichView ? viewType : null;
return _libraryManager.GetNamedView(user, name, parentId.ToString("N"), viewType, sortName, null, cancellationToken);
}
public Task<UserView> GetUserView(Folder parent, string viewType, bool enableRichView, string sortName, CancellationToken cancellationToken)
{
viewType = enableRichView ? viewType : null;
return _libraryManager.GetShadowView(parent, viewType, sortName, null, cancellationToken);
return _libraryManager.GetShadowView(parent, viewType, sortName, cancellationToken);
}
public List<Tuple<BaseItem, List<BaseItem>>> GetLatestItems(LatestItemsQuery request)

View File

@ -2296,7 +2296,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
public async Task<Folder> GetInternalLiveTvFolder(CancellationToken cancellationToken)
{
var name = _localization.GetLocalizedString("ViewTypeLiveTV");
return await _libraryManager.GetNamedView(name, "livetv", name, cancellationToken).ConfigureAwait(false);
return await _libraryManager.GetNamedView(name, CollectionType.LiveTv, name, cancellationToken).ConfigureAwait(false);
}
public async Task<TunerHostInfo> SaveTunerHost(TunerHostInfo info)

View File

@ -25,7 +25,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
private readonly IServerConfigurationManager _config;
private readonly IFileSystem _fileSystem;
public const int MigrationVersion = 6;
public const int MigrationVersion = 7;
public CleanDatabaseScheduledTask(ILibraryManager libraryManager, IItemRepository itemRepo, ILogger logger, IServerConfigurationManager config, IFileSystem fileSystem)
{
@ -75,10 +75,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
{
var itemIds = _libraryManager.GetItemIds(new InternalItemsQuery
{
IsCurrentSchema = false,
// These are constantly getting regenerated so don't bother with them here
ExcludeItemTypes = new[] { typeof(LiveTvProgram).Name }
IsCurrentSchema = false
});
var numComplete = 0;

View File

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

View File

@ -140,7 +140,7 @@ namespace MediaBrowser.ServerApplication
if (!duplicate.WaitForExit(10000))
{
_logger.Info("The duplicate process did not exit.");
return true;
//return true;
}
}