aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/Sqlite/SQLiteUserRepository.cs
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2013-04-05 21:03:38 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2013-04-05 21:03:38 -0400
commit9c7f492e2cd3b940d8041e6949cea9898a057826 (patch)
treeb801589b7e167125b7fae7add6b9a914daeeaa10 /MediaBrowser.Server.Implementations/Sqlite/SQLiteUserRepository.cs
parent9794c8fb1adc01823a9bdd469b470390fee0ebcd (diff)
fixed an issue with the video image provider requiring two-pass refreshing
Diffstat (limited to 'MediaBrowser.Server.Implementations/Sqlite/SQLiteUserRepository.cs')
-rw-r--r--MediaBrowser.Server.Implementations/Sqlite/SQLiteUserRepository.cs53
1 files changed, 41 insertions, 12 deletions
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
@@ -46,6 +46,18 @@ namespace MediaBrowser.Server.Implementations.Sqlite
private readonly IApplicationPaths _appPaths;
/// <summary>
+ /// Gets a value indicating whether [enable delayed commands].
+ /// </summary>
+ /// <value><c>true</c> if [enable delayed commands]; otherwise, <c>false</c>.</value>
+ protected override bool EnableDelayedCommands
+ {
+ get
+ {
+ return false;
+ }
+ }
+
+ /// <summary>
/// Initializes a new instance of the <see cref="SQLiteUserDataRepository" /> class.
/// </summary>
/// <param name="appPaths">The app paths.</param>
@@ -97,7 +109,7 @@ namespace MediaBrowser.Server.Implementations.Sqlite
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
/// <exception cref="System.ArgumentNullException">user</exception>
- 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();
+ }
+ }
}
/// <summary>