Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

(#809) LoadErrorsAsync updated to load errors for a list of tables. #812

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,30 @@ public bool HasErrors(IEnumerable<TableOperationError> errors)
/// <summary>
/// Loads all the sync errors in local store that are recorded for this batch.
/// </summary>
/// <param name="tableNames">The list of tables to load errors for. If empty, all tables are loaded.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe.</param>
/// <returns>A list of sync errors.</returns>
public async Task<IList<TableOperationError>> LoadErrorsAsync(CancellationToken cancellationToken = default)
public async Task<IList<TableOperationError>> LoadErrorsAsync(string[] tableNames, CancellationToken cancellationToken = default)
{
var enumerable = new FuncAsyncPageable<TableOperationError>(nextLink => GetNextPageAsync("", nextLink, cancellationToken));
var errors = new List<TableOperationError>();
await foreach (var error in enumerable)
{
error.Context = Context;
errors.Add(error);
if (tableNames == null || tableNames.Length == 0 || tableNames.Contains(error.TableName))
{
error.Context = Context;
errors.Add(error);
}
}
return errors;
}

/// <summary>
/// Loads all the sync errors in local store that are recorded for this batch.
/// </summary>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe.</param>
/// <returns>A list of sync errors.</returns>
public async Task<IList<TableOperationError>> LoadErrorsAsync(CancellationToken cancellationToken = default)
=> await LoadErrorsAsync(null, cancellationToken);
}
}
14 changes: 9 additions & 5 deletions sdk/dotnet/src/Microsoft.Datasync.Client/Offline/SyncContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ public async Task PushItemsAsync(string[] tableNames, PushOptions options, Cance
PushStatus batchStatus = batch.AbortReason ?? PushStatus.Complete;
try
{
errors.AddRange(await batch.LoadErrorsAsync(cancellationToken).ConfigureAwait(false));
errors.AddRange(await batch.LoadErrorsAsync(tableNames, cancellationToken).ConfigureAwait(false));
}
catch (Exception ex)
{
Expand Down Expand Up @@ -886,11 +886,15 @@ protected virtual async Task<bool> ExecutePushOperationAsync(TableOperation oper
}
}

if (removeFromQueueOnSuccess && error == null)
if (error == null)
{
await OperationsQueue.DeleteOperationByIdAsync(operation.Id, operation.Version, cancellationToken).ConfigureAwait(false);
IList<TableOperationError> errors = (await batch.LoadErrorsAsync(cancellationToken).ConfigureAwait(false))
.Where(e => e.TableName == operation.TableName && (string)e.Item["id"] == operation.Id).ToList();
if (removeFromQueueOnSuccess)
{
await OperationsQueue.DeleteOperationByIdAsync(operation.Id, operation.Version, cancellationToken).ConfigureAwait(false);
}

IList<TableOperationError> errors = (await batch.LoadErrorsAsync(new string[] { operation.TableName }, cancellationToken).ConfigureAwait(false))
.Where(e => (string)e.Item["id"] == operation.Id).ToList();
if (errors.Count > 0)
{
await RemoveErrorsAsync(errors, cancellationToken).ConfigureAwait(false);
Expand Down
Loading