From ddb6ea6f0576a6ba9c6050cc0799ac6b0e3c2fa8 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 3 Jun 2016 20:15:14 -0400 Subject: rework user data --- .../Library/UserDataManager.cs | 98 ++++++---------------- 1 file changed, 24 insertions(+), 74 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Library') diff --git a/MediaBrowser.Server.Implementations/Library/UserDataManager.cs b/MediaBrowser.Server.Implementations/Library/UserDataManager.cs index afbce87a9..c2606dc4b 100644 --- a/MediaBrowser.Server.Implementations/Library/UserDataManager.cs +++ b/MediaBrowser.Server.Implementations/Library/UserDataManager.cs @@ -23,7 +23,8 @@ namespace MediaBrowser.Server.Implementations.Library { public event EventHandler UserDataSaved; - private readonly Dictionary _userData = new Dictionary(StringComparer.OrdinalIgnoreCase); + private readonly ConcurrentDictionary _userData = + new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); private readonly ILogger _logger; private readonly IServerConfigurationManager _config; @@ -64,13 +65,6 @@ namespace MediaBrowser.Server.Implementations.Library try { await Repository.SaveUserData(userId, key, userData, cancellationToken).ConfigureAwait(false); - - var newValue = userData; - - lock (_userData) - { - _userData[GetCacheKey(userId, key)] = newValue; - } } catch (Exception ex) { @@ -80,6 +74,9 @@ namespace MediaBrowser.Server.Implementations.Library } } + var cacheKey = GetCacheKey(userId, item.Id); + _userData.AddOrUpdate(cacheKey, userData, (k, v) => userData); + EventHelper.FireEventIfNotNull(UserDataSaved, this, new UserDataSaveEventArgs { Keys = keys, @@ -122,7 +119,7 @@ namespace MediaBrowser.Server.Implementations.Library throw; } - + } /// @@ -140,7 +137,7 @@ namespace MediaBrowser.Server.Implementations.Library return Repository.GetAllUserData(userId); } - public UserItemData GetUserData(Guid userId, List keys) + public UserItemData GetUserData(Guid userId, Guid itemId, List keys) { if (userId == Guid.Empty) { @@ -150,26 +147,23 @@ namespace MediaBrowser.Server.Implementations.Library { throw new ArgumentNullException("keys"); } - - lock (_userData) + if (keys.Count == 0) { - foreach (var key in keys) - { - var cacheKey = GetCacheKey(userId, key); - UserItemData value; - if (_userData.TryGetValue(cacheKey, out value)) - { - return value; - } + throw new ArgumentException("UserData keys cannot be empty."); + } - value = Repository.GetUserData(userId, key); + var cacheKey = GetCacheKey(userId, itemId); - if (value != null) - { - _userData[cacheKey] = value; - return value; - } - } + return _userData.GetOrAdd(cacheKey, k => GetUserDataInternal(userId, keys)); + } + + private UserItemData GetUserDataInternal(Guid userId, List keys) + { + var userData = Repository.GetUserData(userId, keys); + + if (userData != null) + { + return userData; } if (keys.Count > 0) @@ -184,57 +178,13 @@ namespace MediaBrowser.Server.Implementations.Library return null; } - /// - /// Gets the user data. - /// - /// The user id. - /// The key. - /// Task{UserItemData}. - public UserItemData GetUserData(Guid userId, string key) - { - if (userId == Guid.Empty) - { - throw new ArgumentNullException("userId"); - } - if (string.IsNullOrEmpty(key)) - { - throw new ArgumentNullException("key"); - } - - lock (_userData) - { - var cacheKey = GetCacheKey(userId, key); - UserItemData value; - if (_userData.TryGetValue(cacheKey, out value)) - { - return value; - } - - value = Repository.GetUserData(userId, key); - - if (value == null) - { - value = new UserItemData - { - UserId = userId, - Key = key - }; - } - - _userData[cacheKey] = value; - return value; - } - } - /// /// Gets the internal key. /// - /// The user id. - /// The key. /// System.String. - private string GetCacheKey(Guid userId, string key) + private string GetCacheKey(Guid userId, Guid itemId) { - return userId + key; + return userId.ToString("N") + itemId.ToString("N"); } public UserItemData GetUserData(IHasUserData user, IHasUserData item) @@ -249,7 +199,7 @@ namespace MediaBrowser.Server.Implementations.Library public UserItemData GetUserData(Guid userId, IHasUserData item) { - return GetUserData(userId, item.GetUserDataKeys()); + return GetUserData(userId, item.Id, item.GetUserDataKeys()); } public UserItemDataDto GetUserDataDto(IHasUserData item, User user) -- cgit v1.2.3 From 020b1d9a6425dca8540156ace187fe72dd75f8f1 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 4 Jun 2016 01:51:33 -0400 Subject: add library display settings --- MediaBrowser.Api/StartupWizardService.cs | 1 + .../Configuration/ServerConfiguration.cs | 1 + .../Library/UserViewManager.cs | 6 ++++ .../ApplicationHost.cs | 5 +-- .../MediaBrowser.Server.Startup.Common.csproj | 1 + .../Migrations/FolderViewSettingMigration.cs | 37 ++++++++++++++++++++++ .../MediaBrowser.WebDashboard.csproj | 6 ++++ 7 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 MediaBrowser.Server.Startup.Common/Migrations/FolderViewSettingMigration.cs (limited to 'MediaBrowser.Server.Implementations/Library') diff --git a/MediaBrowser.Api/StartupWizardService.cs b/MediaBrowser.Api/StartupWizardService.cs index 989dea6c6..dbb6478a1 100644 --- a/MediaBrowser.Api/StartupWizardService.cs +++ b/MediaBrowser.Api/StartupWizardService.cs @@ -113,6 +113,7 @@ namespace MediaBrowser.Api config.EnableCustomPathSubFolders = true; config.EnableStandaloneMusicKeys = true; config.EnableCaseSensitiveItemIds = true; + config.EnableFolderView = true; config.SchemaVersion = 89; } diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index df0e42869..e89aafaca 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -198,6 +198,7 @@ namespace MediaBrowser.Model.Configuration public bool EnableAnonymousUsageReporting { get; set; } public bool EnableStandaloneMusicKeys { get; set; } public bool EnableLocalizedGuids { get; set; } + public bool EnableFolderView { get; set; } /// /// Initializes a new instance of the class. diff --git a/MediaBrowser.Server.Implementations/Library/UserViewManager.cs b/MediaBrowser.Server.Implementations/Library/UserViewManager.cs index 6c88f506b..e6a571f07 100644 --- a/MediaBrowser.Server.Implementations/Library/UserViewManager.cs +++ b/MediaBrowser.Server.Implementations/Library/UserViewManager.cs @@ -105,6 +105,12 @@ namespace MediaBrowser.Server.Implementations.Library } } + if (_config.Configuration.EnableFolderView) + { + var name = _localizationManager.GetLocalizedString("ViewType" + CollectionType.Folders); + list.Add(await _libraryManager.GetNamedView(name, CollectionType.Folders, string.Empty, cancellationToken).ConfigureAwait(false)); + } + if (query.IncludeExternalContent) { var channelResult = await _channelManager.GetChannelsInternal(new ChannelQuery diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs index 59a8a4f78..75e3bb7f5 100644 --- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs +++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs @@ -380,7 +380,8 @@ namespace MediaBrowser.Server.Startup.Common { new OmdbEpisodeProviderMigration(ServerConfigurationManager), new MovieDbEpisodeProviderMigration(ServerConfigurationManager), - new DbMigration(ServerConfigurationManager, TaskManager) + new DbMigration(ServerConfigurationManager, TaskManager), + new FolderViewSettingMigration(ServerConfigurationManager, UserManager) }; foreach (var task in migrations) @@ -568,7 +569,7 @@ namespace MediaBrowser.Server.Startup.Common SubtitleEncoder = new SubtitleEncoder(LibraryManager, LogManager.GetLogger("SubtitleEncoder"), ApplicationPaths, FileSystemManager, MediaEncoder, JsonSerializer, HttpClient, MediaSourceManager); RegisterSingleInstance(SubtitleEncoder); - + await displayPreferencesRepo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false); await ConfigureUserDataRepositories().ConfigureAwait(false); await itemRepo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false); diff --git a/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj b/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj index d0769f488..a6d09d343 100644 --- a/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj +++ b/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj @@ -71,6 +71,7 @@ + diff --git a/MediaBrowser.Server.Startup.Common/Migrations/FolderViewSettingMigration.cs b/MediaBrowser.Server.Startup.Common/Migrations/FolderViewSettingMigration.cs new file mode 100644 index 000000000..4049d1754 --- /dev/null +++ b/MediaBrowser.Server.Startup.Common/Migrations/FolderViewSettingMigration.cs @@ -0,0 +1,37 @@ +using System.Linq; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Library; + +namespace MediaBrowser.Server.Startup.Common.Migrations +{ + public class FolderViewSettingMigration : IVersionMigration + { + private readonly IServerConfigurationManager _config; + private readonly IUserManager _userManager; + + public FolderViewSettingMigration(IServerConfigurationManager config, IUserManager userManager) + { + _config = config; + _userManager = userManager; + } + + public void Run() + { + var migrationKey = this.GetType().Name; + var migrationKeyList = _config.Configuration.Migrations.ToList(); + + if (!migrationKeyList.Contains(migrationKey)) + { + if (_config.Configuration.IsStartupWizardCompleted) + { + _config.Configuration.EnableFolderView = _userManager.Users.Any(i => i.Configuration.DisplayFoldersView); + } + + migrationKeyList.Add(migrationKey); + _config.Configuration.Migrations = migrationKeyList.ToArray(); + _config.SaveConfiguration(); + } + + } + } +} diff --git a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj index 1d860ed29..36693ad8e 100644 --- a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj +++ b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj @@ -272,6 +272,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest @@ -308,6 +311,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest -- cgit v1.2.3