Skip to content

Commit da4ebc4

Browse files
read improvements
1 parent df193e2 commit da4ebc4

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

Extensions/AzureBlob/Cosmos.DataTransfer.AzureBlobStorage/AzureBlobDataSink.cs

+8-5
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public async Task WriteToTargetAsync(Func<Stream, Task> writeToStream, IConfigur
4545
var logInterval = TimeSpan.FromMinutes(1);
4646
long totalBytes = 0;
4747

48-
var sw = new Stopwatch();
49-
sw.Start();
48+
var swOpenWrite = new Stopwatch();
49+
swOpenWrite.Start();
5050
await using var blobStream = await blob.OpenWriteAsync(true, new BlockBlobOpenWriteOptions
5151
{
5252
BufferSize = settings.MaxBlockSizeinKB * 1024L,
@@ -62,16 +62,19 @@ public async Task WriteToTargetAsync(Func<Stream, Task> writeToStream, IConfigur
6262
})
6363

6464
}, cancellationToken);
65+
swOpenWrite.Stop();
6566

67+
var swWrite = new Stopwatch();
68+
swWrite.Start();
6669
await writeToStream(blobStream);
67-
68-
sw.Stop();
70+
swWrite.Stop();
6971

72+
logger.LogInformation("{BlobName}: open write for blob took {TotalTime} seconds.", settings.BlobName, swOpenWrite.Elapsed.Seconds);
7073
if (totalBytes != 0)
7174
{
7275
var totalMib = (double) totalBytes / 1024 / 1024;
7376

74-
logger.LogInformation("{BlobName}: transferred {TotalMiB} Mib to Azure Blob in {TotalTime} seconds.", settings.BlobName, totalMib, (double) sw.ElapsedMilliseconds / 1000);
77+
logger.LogInformation("{BlobName}: transferred {TotalMiB} Mib to Azure Blob in {TotalTime} seconds.", settings.BlobName, totalMib, swWrite.Elapsed.Seconds);
7578
}
7679
}
7780

Extensions/AzureTableAPI/Cosmos.DataTransfer.AzureTableAPIExtension/AzureTableAPIDataSourceExtension.cs

+5-14
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,14 @@ public async IAsyncEnumerable<IDataItem> ReadAsync(IConfiguration config, ILogge
2323
var serviceClient = new TableServiceClient(settings.ConnectionString);
2424
var tableClient = serviceClient.GetTableClient(settings.Table);
2525

26-
//Pageable<TableEntity> queryResultsFilter = tableClient.Query<TableEntity>(filter: $"PartitionKey eq '{partitionKey}'");
27-
AsyncPageable<TableEntity> queryResults;
28-
if (!string.IsNullOrWhiteSpace(settings.QueryFilter)) {
29-
queryResults = tableClient.QueryAsync<TableEntity>(filter: settings.QueryFilter);
30-
} else {
31-
queryResults = tableClient.QueryAsync<TableEntity>();
32-
}
26+
var queryResults = !string.IsNullOrWhiteSpace(settings.QueryFilter)
27+
? tableClient.QueryAsync<TableEntity>(filter: settings.QueryFilter, cancellationToken: cancellationToken)
28+
: tableClient.QueryAsync<TableEntity>(cancellationToken: cancellationToken);
3329

34-
var enumerator = queryResults.GetAsyncEnumerator();
35-
while (await enumerator.MoveNextAsync())
30+
await foreach (var entity in queryResults.WithCancellation(cancellationToken))
3631
{
37-
yield return new AzureTableAPIDataItem(enumerator.Current, settings.PartitionKeyFieldName, settings.RowKeyFieldName);
32+
yield return new AzureTableAPIDataItem(entity, settings.PartitionKeyFieldName, settings.RowKeyFieldName);
3833
}
39-
//do
40-
//{
41-
// yield return new AzureTableAPIDataItem(enumerator.Current, settings.PartitionKeyFieldName, settings.RowKeyFieldName);
42-
//} while (await enumerator.MoveNextAsync());
4334
}
4435

4536
public IEnumerable<IDataExtensionSettings> GetSettings()

0 commit comments

Comments
 (0)