Skip to content

Commit 6db0747

Browse files
committed
minor optimizations and refactoring
1 parent e9c32a2 commit 6db0747

File tree

6 files changed

+54
-31
lines changed

6 files changed

+54
-31
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
This project builds on top of [TableStorage.Abstractions](https://github.com/Tazmainiandevil/TableStorage.Abstractions) (a repository wrapper over [Azure Table Storage](https://docs.microsoft.com/en-us/azure/cosmos-db/table-storage-how-to-use-dotnet)) and [TableStorage.Abstractions.TableEntityConverters](https://github.com/giometrix/TableStorage.Abstractions.TableEntityConverters) such that objects to be serialized to and from Azure Table Storage are Plain Old CLR Objects (POCO) rather than TableEntities.
77

8-
### For secondary index support, check out [TableStorage.Abstractions.POCO.SecondaryIndexes](https://github.com/giometrix/TableStorage.Abstractions.POCO/tree/master/src/TableStorage.Abstractions.POCO.SecondaryIndexes).
8+
## For secondary index support, check out [TableStorage.Abstractions.POCO.SecondaryIndexes](https://github.com/giometrix/TableStorage.Abstractions.POCO/tree/master/src/TableStorage.Abstractions.POCO.SecondaryIndexes)
99

1010
## Examples
1111
Assume we have the following two classes, which we wish to serialize to and from Azure Table Storage:
@@ -147,7 +147,6 @@ To retrieve the record, we can use ```PartitionKey``` to build the multi-part ke
147147
var record = tableStore.GetRecord(new PartitionKey(1, 22), 1);
148148
```
149149

150-
151150
#### Fixed Keys
152151
Fixed keys are really just a specialization of calculated keys. A scenario that you may run into sometimes is where you only need a single key, which is the case when you only query the data using point queries ("get by id"). In this scenario, you'll probably choose to supply a partition key and not a row key since in this case you'd get better throughput using partition keys in a high volume system (again, we are assuming a point-query-only scenario).
153152

src/TableStorage.Abstractions.POCO.SecondaryIndexes/PocoStoreIndexer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ public static async Task ReindexAsync<T, TPartitionKey, TRowKey>(this IPocoTable
490490
{
491491
foreach (var record in result.Items)
492492
{
493-
await semaphore.WaitAsync(TimeSpan.FromSeconds(20));
493+
await semaphore.WaitAsync(TimeSpan.FromSeconds(20)).ConfigureAwait(false);
494494
//Task task = indexStore.InsertOrReplaceAsync(record); //this line worked in the unit tests but not in a console app. Not sure why.
495495
var task = (Task) insertOrReplaceAsync.Invoke(indexStore, new object[] { record });
496496
task.ContinueWith(r =>
@@ -512,7 +512,7 @@ public static async Task ReindexAsync<T, TPartitionKey, TRowKey>(this IPocoTable
512512
while (semaphore.CurrentCount < maxDegreeOfParallelism)
513513
{
514514

515-
await Task.Delay(5);
515+
await Task.Delay(5).ConfigureAwait(false);
516516
}
517517
recordsIndexedCallback?.Invoke(count);
518518
}

src/TableStorage.Abstractions.POCO.SecondaryIndexes/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
This project builds on top of [TableStorage.Abstractions.POCO](https://github.com/giometrix/TableStorage.Abstractions.POCO) to introduce "secondary indexes" to [Azure Table Storage](https://github.com/giometrix/TableStorage.Abstractions.POCO). Internally this library uses an [intra/inter partition (or table) secondary index pattern](https://docs.microsoft.com/en-us/azure/storage/tables/table-storage-design-patterns). When data gets mutated on your table store, the library takes care of reflecting the change in your secondary indexes.
55

66
## Caveats And Notes
7-
1. Indexes are managed through a library, _not_ Table Storage, thus data mutated outside of the library will not automatically be reflected in your indexes.
8-
2. Though Azure Table Storage does offer transactions within partitions, this library does not leverage this at this time.
9-
3. This library is intended for Azure Table Storage, not CosmosDB, which offers an Azure Table Storage API. CosmosDB does offer secondary indexes, so this library may not be as useful there.
7+
1. Indexes are managed through a library, _not_ Table Storage, thus data mutated outside of the library will not automatically be reflected in your indexes.
8+
2. Though Azure Table Storage does offer transactions within partitions, this library does not leverage this at this time.
9+
3. This library is intended for Azure Table Storage, not CosmosDB, which offers an Azure Table Storage API. CosmosDB does offer secondary indexes, so this library may not be as useful there.
1010

1111
## Examples
1212
Note that it may be useful to read about [TableStorage.Abstractions.POCO](https://github.com/giometrix/TableStorage.Abstractions.POCO) to better understand the examples below.

src/TableStorage.Abstractions.POCO/PocoTableStore.cs

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,11 @@ public IObservable<T> GetRecordsByFilterObservable(Func<T, bool> filter, int sta
381381
/// <returns>Task.</returns>
382382
public async Task CreateTableAsync()
383383
{
384-
await _tableStore.CreateTableAsync();
385-
if (OnTableCreatedAsync != null) await OnTableCreatedAsync(_tableName, this);
384+
await _tableStore.CreateTableAsync().ConfigureAwait(false);
385+
if (OnTableCreatedAsync != null)
386+
{
387+
await OnTableCreatedAsync(_tableName, this).ConfigureAwait(false);
388+
}
386389
}
387390

388391
/// <summary>
@@ -407,8 +410,11 @@ public async Task InsertAsync(T record)
407410

408411
var entity = CreateEntity(record);
409412

410-
await _tableStore.InsertAsync(entity);
411-
if (OnRecordInsertedOrUpdatedAsync != null) await OnRecordInsertedOrUpdatedAsync(record);
413+
await _tableStore.InsertAsync(entity).ConfigureAwait(false);
414+
if (OnRecordInsertedOrUpdatedAsync != null)
415+
{
416+
await OnRecordInsertedOrUpdatedAsync(record).ConfigureAwait(false);
417+
}
412418
}
413419

414420
/// <summary>
@@ -424,8 +430,11 @@ public async Task InsertOrReplaceAsync(T record)
424430

425431
var entity = CreateEntity(record);
426432

427-
await _tableStore.InsertOrReplaceAsync(entity);
428-
if (OnRecordInsertedOrUpdatedAsync != null) await OnRecordInsertedOrUpdatedAsync(record);
433+
await _tableStore.InsertOrReplaceAsync(entity).ConfigureAwait(false);
434+
if (OnRecordInsertedOrUpdatedAsync != null)
435+
{
436+
await OnRecordInsertedOrUpdatedAsync(record).ConfigureAwait(false);
437+
}
429438
}
430439

431440
/// <summary>
@@ -440,8 +449,11 @@ public async Task InsertAsync(IEnumerable<T> records)
440449
throw new ArgumentNullException(nameof(records));
441450

442451
var entities = CreateEntities(records);
443-
await _tableStore.InsertAsync(entities);
444-
if (OnRecordsInsertedAsync != null) await OnRecordsInsertedAsync(records);
452+
await _tableStore.InsertAsync(entities).ConfigureAwait(false);
453+
if (OnRecordsInsertedAsync != null)
454+
{
455+
await OnRecordsInsertedAsync(records).ConfigureAwait(false);
456+
}
445457
}
446458

447459
/// <summary>
@@ -452,8 +464,11 @@ public async Task InsertAsync(IEnumerable<T> records)
452464
public async Task UpdateAsync(T record)
453465
{
454466
var entity = CreateEntityWithEtag(record);
455-
await _tableStore.UpdateAsync(entity);
456-
if (OnRecordInsertedOrUpdatedAsync != null) await OnRecordInsertedOrUpdatedAsync(record);
467+
await _tableStore.UpdateAsync(entity).ConfigureAwait(false);
468+
if (OnRecordInsertedOrUpdatedAsync != null)
469+
{
470+
await OnRecordInsertedOrUpdatedAsync(record).ConfigureAwait(false);
471+
}
457472
}
458473

459474
/// <summary>
@@ -464,8 +479,11 @@ public async Task UpdateAsync(T record)
464479
public async Task UpdateUsingWildcardEtagAsync(T record)
465480
{
466481
var entity = CreateEntity(record);
467-
await _tableStore.UpdateUsingWildcardEtagAsync(entity);
468-
if (OnRecordInsertedOrUpdatedAsync != null) await OnRecordInsertedOrUpdatedAsync(record);
482+
await _tableStore.UpdateUsingWildcardEtagAsync(entity).ConfigureAwait(false);
483+
if (OnRecordInsertedOrUpdatedAsync != null)
484+
{
485+
await OnRecordInsertedOrUpdatedAsync(record).ConfigureAwait(false);
486+
}
469487
}
470488

471489
/// <summary>
@@ -476,8 +494,11 @@ public async Task UpdateUsingWildcardEtagAsync(T record)
476494
public async Task DeleteAsync(T record)
477495
{
478496
var entity = CreateEntityWithEtag(record);
479-
await _tableStore.DeleteAsync(entity);
480-
if (OnRecordDeletedAsync != null) await OnRecordDeletedAsync(record);
497+
await _tableStore.DeleteAsync(entity).ConfigureAwait(false);
498+
if (OnRecordDeletedAsync != null)
499+
{
500+
await OnRecordDeletedAsync(record).ConfigureAwait(false);
501+
}
481502
}
482503

483504
/// <summary>
@@ -488,8 +509,11 @@ public async Task DeleteAsync(T record)
488509
public async Task DeleteUsingWildcardEtagAsync(T record)
489510
{
490511
var entity = CreateEntity(record);
491-
await _tableStore.DeleteUsingWildcardEtagAsync(entity);
492-
if (OnRecordDeletedAsync != null) await OnRecordDeletedAsync(record);
512+
await _tableStore.DeleteUsingWildcardEtagAsync(entity).ConfigureAwait(false);
513+
if (OnRecordDeletedAsync != null)
514+
{
515+
await OnRecordDeletedAsync(record).ConfigureAwait(false);
516+
}
493517
}
494518

495519
/// <summary>
@@ -498,8 +522,11 @@ public async Task DeleteUsingWildcardEtagAsync(T record)
498522
/// <returns>Task.</returns>
499523
public async Task DeleteTableAsync()
500524
{
501-
await _tableStore.DeleteTableAsync();
502-
if (OnTableDeletedAsync != null) await OnTableDeletedAsync(_tableName, this);
525+
await _tableStore.DeleteTableAsync().ConfigureAwait(false);
526+
if (OnTableDeletedAsync != null)
527+
{
528+
await OnTableDeletedAsync(_tableName, this).ConfigureAwait(false);
529+
}
503530
}
504531

505532
/// <summary>
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
namespace TableStorage.Abstractions.POCO.Tests
22
{
3-
public partial class PocoTableStoreTests
4-
{
5-
public class PartitionKey
3+
public class PartitionKey
64
{
75
public PartitionKey(int companyId, int departmentId)
86
{
@@ -12,6 +10,5 @@ public PartitionKey(int companyId, int departmentId)
1210
public int CompanyId { get; }
1311
public int DepartmentId { get; }
1412
}
15-
16-
}
13+
1714
}

tests/TableStorage.Abstractions.POCO.Tests/PocoTableStoreTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace TableStorage.Abstractions.POCO.Tests
1111
{
1212
[TestClass]
13-
public partial class PocoTableStoreTests
13+
public class PocoTableStoreTests
1414
{
1515
private PocoTableStore<Employee, int, int> tableStore;
1616

0 commit comments

Comments
 (0)