From 7cd41a6ed62c46006307add9de92e0b329bd0edc Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 21 Feb 2014 00:04:11 -0500 Subject: easier user library setup --- .../Library/LibraryManager.cs | 64 ++++++---------------- 1 file changed, 18 insertions(+), 46 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Library/LibraryManager.cs') diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index c2044476a..5bc1ff45a 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -153,12 +153,6 @@ namespace MediaBrowser.Server.Implementations.Library } } - /// - /// The _user root folders - /// - private readonly ConcurrentDictionary _userRootFolders = - new ConcurrentDictionary(); - private readonly IFileSystem _fileSystem; /// @@ -586,7 +580,7 @@ namespace MediaBrowser.Server.Implementations.Library var flattenFolderDepth = isPhysicalRoot ? 2 : 0; var fileSystemDictionary = FileData.GetFilteredFileSystemEntries(directoryService, args.Path, _fileSystem, _logger, args, flattenFolderDepth: flattenFolderDepth, resolveShortcuts: isPhysicalRoot || args.IsVf); - + // Need to remove subpaths that may have been resolved from shortcuts // Example: if \\server\movies exists, then strip out \\server\movies\action if (isPhysicalRoot) @@ -701,20 +695,18 @@ namespace MediaBrowser.Server.Implementations.Library return rootFolder; } - /// - /// Gets the user root folder. - /// - /// The user root path. - /// UserRootFolder. - public UserRootFolder GetUserRootFolder(string userRootPath) + private UserRootFolder _userRootFolder; + public Folder GetUserRootFolder() { - return _userRootFolders.GetOrAdd(userRootPath, key => RetrieveItem(userRootPath.GetMBId(typeof(UserRootFolder))) as UserRootFolder ?? - (UserRootFolder)ResolvePath(new DirectoryInfo(userRootPath))); - } + if (_userRootFolder == null) + { + var userRootPath = ConfigurationManager.ApplicationPaths.DefaultUserViewsPath; - public Person GetPersonSync(string name) - { - return GetItemByName(ConfigurationManager.ApplicationPaths.PeoplePath, name); + _userRootFolder = RetrieveItem(userRootPath.GetMBId(typeof(UserRootFolder))) as UserRootFolder ?? + (UserRootFolder)ResolvePath(new DirectoryInfo(userRootPath)); + } + + return _userRootFolder; } /// @@ -1001,7 +993,7 @@ namespace MediaBrowser.Server.Implementations.Library // Just run the scheduled task so that the user can see it _taskManager.QueueScheduledTask(); } - + /// /// Validates the media library internal. /// @@ -1035,19 +1027,15 @@ namespace MediaBrowser.Server.Implementations.Library progress.Report(1); - foreach (var folder in _userManager.Users.Select(u => u.RootFolder).Distinct()) - { - await ValidateCollectionFolders(folder, cancellationToken).ConfigureAwait(false); - } + var userRoot = GetUserRootFolder(); + await userRoot.RefreshMetadata(cancellationToken).ConfigureAwait(false); + + await userRoot.ValidateChildren(new Progress(), cancellationToken, new MetadataRefreshOptions(), recursive: false).ConfigureAwait(false); progress.Report(2); var innerProgress = new ActionableProgress(); - innerProgress.RegisterAction(pct => progress.Report(2 + pct * .13)); - - innerProgress = new ActionableProgress(); - innerProgress.RegisterAction(pct => progress.Report(2 + pct * .73)); // Now validate the entire media library @@ -1118,22 +1106,6 @@ namespace MediaBrowser.Server.Implementations.Library progress.Report(100); } - /// - /// Validates only the collection folders for a User and goes no further - /// - /// The user root folder. - /// The cancellation token. - /// Task. - private async Task ValidateCollectionFolders(UserRootFolder userRootFolder, CancellationToken cancellationToken) - { - _logger.Info("Validating collection folders within {0}", userRootFolder.Path); - await userRootFolder.RefreshMetadata(cancellationToken).ConfigureAwait(false); - - cancellationToken.ThrowIfCancellationRequested(); - - await userRootFolder.ValidateChildren(new Progress(), cancellationToken, new MetadataRefreshOptions(), recursive: false).ConfigureAwait(false); - } - /// /// Gets the default view. /// @@ -1150,7 +1122,7 @@ namespace MediaBrowser.Server.Implementations.Library /// IEnumerable{VirtualFolderInfo}. public IEnumerable GetVirtualFolders(User user) { - return GetView(user.RootFolderPath); + return GetDefaultVirtualFolders(); } /// @@ -1399,7 +1371,7 @@ namespace MediaBrowser.Server.Implementations.Library { await _providerManagerFactory().SaveMetadata(item, updateReason).ConfigureAwait(false); } - + item.DateLastSaved = DateTime.UtcNow; _logger.Debug("Saving {0} to database.", item.Path ?? item.Name); -- cgit v1.2.3