From 9c7f492e2cd3b940d8041e6949cea9898a057826 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 5 Apr 2013 21:03:38 -0400 Subject: fixed an issue with the video image provider requiring two-pass refreshing --- .../Sqlite/SQLiteUserRepository.cs | 53 +++++++++++++++++----- 1 file changed, 41 insertions(+), 12 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Sqlite/SQLiteUserRepository.cs') diff --git a/MediaBrowser.Server.Implementations/Sqlite/SQLiteUserRepository.cs b/MediaBrowser.Server.Implementations/Sqlite/SQLiteUserRepository.cs index 812c98789..f55b13d19 100644 --- a/MediaBrowser.Server.Implementations/Sqlite/SQLiteUserRepository.cs +++ b/MediaBrowser.Server.Implementations/Sqlite/SQLiteUserRepository.cs @@ -45,6 +45,18 @@ namespace MediaBrowser.Server.Implementations.Sqlite /// private readonly IApplicationPaths _appPaths; + /// + /// Gets a value indicating whether [enable delayed commands]. + /// + /// true if [enable delayed commands]; otherwise, false. + protected override bool EnableDelayedCommands + { + get + { + return false; + } + } + /// /// Initializes a new instance of the class. /// @@ -97,7 +109,7 @@ namespace MediaBrowser.Server.Implementations.Sqlite /// The cancellation token. /// Task. /// user - public Task SaveUser(User user, CancellationToken cancellationToken) + public async Task SaveUser(User user, CancellationToken cancellationToken) { if (user == null) { @@ -109,20 +121,37 @@ namespace MediaBrowser.Server.Implementations.Sqlite throw new ArgumentNullException("cancellationToken"); } - return Task.Run(() => - { - cancellationToken.ThrowIfCancellationRequested(); + cancellationToken.ThrowIfCancellationRequested(); - var serialized = _jsonSerializer.SerializeToBytes(user); + var serialized = _jsonSerializer.SerializeToBytes(user); - cancellationToken.ThrowIfCancellationRequested(); + cancellationToken.ThrowIfCancellationRequested(); - var cmd = connection.CreateCommand(); - cmd.CommandText = "replace into users (guid, data) values (@1, @2)"; - cmd.AddParam("@1", user.Id); - cmd.AddParam("@2", serialized); - QueueCommand(cmd); - }); + var cmd = connection.CreateCommand(); + cmd.CommandText = "replace into users (guid, data) values (@1, @2)"; + cmd.AddParam("@1", user.Id); + cmd.AddParam("@2", serialized); + + using (var tran = connection.BeginTransaction()) + { + try + { + cmd.Transaction = tran; + + await cmd.ExecuteNonQueryAsync(cancellationToken); + + tran.Commit(); + } + catch (OperationCanceledException) + { + tran.Rollback(); + } + catch (Exception e) + { + Logger.ErrorException("Failed to commit transaction.", e); + tran.Rollback(); + } + } } /// -- cgit v1.2.3