From 9f8a1b30a1ecec0af3c48bcb30e035938f93218c Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 2 Oct 2013 12:58:30 -0400 Subject: moved user data cache to manager class --- .../Persistence/SqliteUserDataRepository.cs | 45 +--------------------- 1 file changed, 2 insertions(+), 43 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Persistence/SqliteUserDataRepository.cs') diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteUserDataRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteUserDataRepository.cs index 20b3ff251..e58bd2506 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteUserDataRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteUserDataRepository.cs @@ -4,7 +4,6 @@ using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Serialization; using System; -using System.Collections.Concurrent; using System.Data; using System.IO; using System.Threading; @@ -16,8 +15,6 @@ namespace MediaBrowser.Server.Implementations.Persistence { private readonly ILogger _logger; - private readonly ConcurrentDictionary _userData = new ConcurrentDictionary(); - private readonly SemaphoreSlim _writeLock = new SemaphoreSlim(1, 1); private IDbConnection _connection; @@ -113,7 +110,7 @@ namespace MediaBrowser.Server.Implementations.Persistence /// userId /// or /// userDataId - public async Task SaveUserData(Guid userId, string key, UserItemData userData, CancellationToken cancellationToken) + public Task SaveUserData(Guid userId, string key, UserItemData userData, CancellationToken cancellationToken) { if (userData == null) { @@ -132,34 +129,7 @@ namespace MediaBrowser.Server.Implementations.Persistence throw new ArgumentNullException("key"); } - cancellationToken.ThrowIfCancellationRequested(); - - try - { - await PersistUserData(userId, key, userData, cancellationToken).ConfigureAwait(false); - - var newValue = userData; - - // Once it succeeds, put it into the dictionary to make it available to everyone else - _userData.AddOrUpdate(GetInternalKey(userId, key), newValue, delegate { return newValue; }); - } - catch (Exception ex) - { - _logger.ErrorException("Error saving user data", ex); - - throw; - } - } - - /// - /// Gets the internal key. - /// - /// The user id. - /// The key. - /// System.String. - private string GetInternalKey(Guid userId, string key) - { - return userId + key; + return PersistUserData(userId, key, userData, cancellationToken); } /// @@ -255,17 +225,6 @@ namespace MediaBrowser.Server.Implementations.Persistence throw new ArgumentNullException("key"); } - return _userData.GetOrAdd(GetInternalKey(userId, key), keyName => RetrieveUserData(userId, key)); - } - - /// - /// Retrieves the user data. - /// - /// The user id. - /// The key. - /// Task{UserItemData}. - private UserItemData RetrieveUserData(Guid userId, string key) - { using (var cmd = _connection.CreateCommand()) { cmd.CommandText = "select rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate from userdata where key = @key and userId=@userId"; -- cgit v1.2.3