|
@@ -135,7 +135,7 @@ namespace MediaBrowser.Server.Implementations.Sqlite
|
|
/// <summary>
|
|
/// <summary>
|
|
/// The _write lock
|
|
/// The _write lock
|
|
/// </summary>
|
|
/// </summary>
|
|
- private readonly SemaphoreSlim _writeLock = new SemaphoreSlim(1,1);
|
|
|
|
|
|
+ private readonly SemaphoreSlim _writeLock = new SemaphoreSlim(1, 1);
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Prepares the statements.
|
|
/// Prepares the statements.
|
|
@@ -172,13 +172,34 @@ namespace MediaBrowser.Server.Implementations.Sqlite
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <returns>Task.</returns>
|
|
/// <returns>Task.</returns>
|
|
/// <exception cref="System.ArgumentNullException">item</exception>
|
|
/// <exception cref="System.ArgumentNullException">item</exception>
|
|
- public async Task SaveItem(BaseItem item, CancellationToken cancellationToken)
|
|
|
|
|
|
+ public Task SaveItem(BaseItem item, CancellationToken cancellationToken)
|
|
{
|
|
{
|
|
if (item == null)
|
|
if (item == null)
|
|
{
|
|
{
|
|
throw new ArgumentNullException("item");
|
|
throw new ArgumentNullException("item");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ return SaveItems(new[] { item }, cancellationToken);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Saves the items.
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="items">The items.</param>
|
|
|
|
+ /// <param name="cancellationToken">The cancellation token.</param>
|
|
|
|
+ /// <returns>Task.</returns>
|
|
|
|
+ /// <exception cref="System.ArgumentNullException">
|
|
|
|
+ /// items
|
|
|
|
+ /// or
|
|
|
|
+ /// cancellationToken
|
|
|
|
+ /// </exception>
|
|
|
|
+ public async Task SaveItems(IEnumerable<BaseItem> items, CancellationToken cancellationToken)
|
|
|
|
+ {
|
|
|
|
+ if (items == null)
|
|
|
|
+ {
|
|
|
|
+ throw new ArgumentNullException("items");
|
|
|
|
+ }
|
|
|
|
+
|
|
if (cancellationToken == null)
|
|
if (cancellationToken == null)
|
|
{
|
|
{
|
|
throw new ArgumentNullException("cancellationToken");
|
|
throw new ArgumentNullException("cancellationToken");
|
|
@@ -186,8 +207,6 @@ namespace MediaBrowser.Server.Implementations.Sqlite
|
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
- var serialized = _jsonSerializer.SerializeToBytes(item);
|
|
|
|
-
|
|
|
|
await _writeLock.WaitAsync(cancellationToken).ConfigureAwait(false);
|
|
await _writeLock.WaitAsync(cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
SQLiteTransaction transaction = null;
|
|
SQLiteTransaction transaction = null;
|
|
@@ -196,13 +215,18 @@ namespace MediaBrowser.Server.Implementations.Sqlite
|
|
{
|
|
{
|
|
transaction = Connection.BeginTransaction();
|
|
transaction = Connection.BeginTransaction();
|
|
|
|
|
|
- _saveItemCommand.Parameters[0].Value = item.Id;
|
|
|
|
- _saveItemCommand.Parameters[1].Value = item.GetType().FullName;
|
|
|
|
- _saveItemCommand.Parameters[2].Value = serialized;
|
|
|
|
|
|
+ foreach (var item in items)
|
|
|
|
+ {
|
|
|
|
+ cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
+
|
|
|
|
+ _saveItemCommand.Parameters[0].Value = item.Id;
|
|
|
|
+ _saveItemCommand.Parameters[1].Value = item.GetType().FullName;
|
|
|
|
+ _saveItemCommand.Parameters[2].Value = _jsonSerializer.SerializeToBytes(item);
|
|
|
|
|
|
- _saveItemCommand.Transaction = transaction;
|
|
|
|
|
|
+ _saveItemCommand.Transaction = transaction;
|
|
|
|
|
|
- await _saveItemCommand.ExecuteNonQueryAsync(cancellationToken);
|
|
|
|
|
|
+ await _saveItemCommand.ExecuteNonQueryAsync(cancellationToken);
|
|
|
|
+ }
|
|
|
|
|
|
transaction.Commit();
|
|
transaction.Commit();
|
|
}
|
|
}
|
|
@@ -400,7 +424,7 @@ namespace MediaBrowser.Server.Implementations.Sqlite
|
|
foreach (var child in children)
|
|
foreach (var child in children)
|
|
{
|
|
{
|
|
_saveChildrenCommand.Transaction = transaction;
|
|
_saveChildrenCommand.Transaction = transaction;
|
|
-
|
|
|
|
|
|
+
|
|
_saveChildrenCommand.Parameters[0].Value = id;
|
|
_saveChildrenCommand.Parameters[0].Value = id;
|
|
_saveChildrenCommand.Parameters[1].Value = child.Id;
|
|
_saveChildrenCommand.Parameters[1].Value = child.Id;
|
|
|
|
|