From b16f0578e241c189e5e9e09b7f1f09e3f04a8bfd Mon Sep 17 00:00:00 2001 From: Kevin J Lambert <784826+Yuck@users.noreply.github.com> Date: Thu, 3 Aug 2023 10:33:55 -0400 Subject: [PATCH] #13 - DynamoDB RetrievalHandler GetList should be using Query and not Scan (closes #13) --- .../Handlers/RetrievalHandler.cs | 35 ++++++++++++------- .../YuckQi.Data.DocumentDb.DynamoDb.csproj | 2 +- .../YuckQi.Data.DocumentDb.MongoDb.csproj | 2 +- .../YuckQi.Data.MemDb.csproj | 2 +- .../YuckQi.Data.Sql.Dapper.MySql.csproj | 2 +- .../YuckQi.Data.Sql.Dapper.Oracle.csproj | 2 +- .../YuckQi.Data.Sql.Dapper.SqlServer.csproj | 2 +- .../YuckQi.Data.Sql.Dapper.csproj | 2 +- .../YuckQi.Data.Sql.EntityFramework.csproj | 2 +- src/YuckQi.Data/YuckQi.Data.csproj | 2 +- 10 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/YuckQi.Data.DocumentDb.DynamoDb/Handlers/RetrievalHandler.cs b/src/YuckQi.Data.DocumentDb.DynamoDb/Handlers/RetrievalHandler.cs index e8758f9..10f77c4 100644 --- a/src/YuckQi.Data.DocumentDb.DynamoDb/Handlers/RetrievalHandler.cs +++ b/src/YuckQi.Data.DocumentDb.DynamoDb/Handlers/RetrievalHandler.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using Amazon.DynamoDBv2.DataModel; +using Amazon.DynamoDBv2.DataModel; using Amazon.DynamoDBv2.DocumentModel; using YuckQi.Data.DocumentDb.DynamoDb.Extensions; using YuckQi.Data.Filtering; @@ -80,9 +75,8 @@ public RetrievalHandler(Func hashKeyValueFactory, Func(); var filter = parameters.ToQueryFilter(); var search = table.Query(filter); - var results = await search.GetRemainingAsync(cancellationToken); - var result = results.SingleOrDefault(); - var document = scope.FromDocument(result); + var documents = await GetDocuments(scope, search, cancellationToken); + var document = documents.SingleOrDefault(); var entity = MapToEntity(document); return entity; @@ -105,12 +99,27 @@ protected override async Task> DoGetList(IReadOnlyC throw new ArgumentNullException(nameof(scope)); var table = scope.GetTargetTable(); - var filter = parameters?.ToScanFilter(); - var search = table.Scan(filter); - var results = await search.GetRemainingAsync(cancellationToken); - var documents = scope.FromDocuments(results); + var filter = parameters?.ToQueryFilter(); + var search = table.Query(filter); + var documents = await GetDocuments(scope, search, cancellationToken); var entities = MapToEntityCollection(documents); return entities; } + + private static async Task> GetDocuments(TScope? scope, Search? search, CancellationToken cancellationToken) + { + if (scope == null) + throw new ArgumentNullException(nameof(scope)); + if (search == null) + throw new ArgumentNullException(nameof(search)); + + var documents = new List(); + + while (! search.IsDone) + documents.AddRange(await search.GetNextSetAsync(cancellationToken)); + documents.AddRange(await search.GetRemainingAsync(cancellationToken)); + + return scope.FromDocuments(documents); + } } diff --git a/src/YuckQi.Data.DocumentDb.DynamoDb/YuckQi.Data.DocumentDb.DynamoDb.csproj b/src/YuckQi.Data.DocumentDb.DynamoDb/YuckQi.Data.DocumentDb.DynamoDb.csproj index 619963b..6bec1aa 100644 --- a/src/YuckQi.Data.DocumentDb.DynamoDb/YuckQi.Data.DocumentDb.DynamoDb.csproj +++ b/src/YuckQi.Data.DocumentDb.DynamoDb/YuckQi.Data.DocumentDb.DynamoDb.csproj @@ -5,7 +5,7 @@ enable true Kevin J Lambert - 6.3.2 + 6.3.3 An implementation of YuckQi.Data for Amazon DynamoDB databases. YuckQi.Data https://github.com/Yuck/YuckQi.Data.git diff --git a/src/YuckQi.Data.DocumentDb.MongoDb/YuckQi.Data.DocumentDb.MongoDb.csproj b/src/YuckQi.Data.DocumentDb.MongoDb/YuckQi.Data.DocumentDb.MongoDb.csproj index 16663d5..e5a8cac 100644 --- a/src/YuckQi.Data.DocumentDb.MongoDb/YuckQi.Data.DocumentDb.MongoDb.csproj +++ b/src/YuckQi.Data.DocumentDb.MongoDb/YuckQi.Data.DocumentDb.MongoDb.csproj @@ -5,7 +5,7 @@ enable true Kevin J Lambert - 6.3.2 + 6.3.3 An implementation of YuckQi.Data for MongoDB databases. YuckQi.Data https://github.com/Yuck/YuckQi.Data.git diff --git a/src/YuckQi.Data.MemDb/YuckQi.Data.MemDb.csproj b/src/YuckQi.Data.MemDb/YuckQi.Data.MemDb.csproj index 295ca9b..48142db 100644 --- a/src/YuckQi.Data.MemDb/YuckQi.Data.MemDb.csproj +++ b/src/YuckQi.Data.MemDb/YuckQi.Data.MemDb.csproj @@ -5,7 +5,7 @@ enable true Kevin J Lambert - 6.3.2 + 6.3.3 An implementation of YuckQi.Data for a in-memory "database" (ConcurrentDictionary), ideal for rapid development without external dependencies. YuckQi.Data https://github.com/Yuck/YuckQi.Data.git diff --git a/src/YuckQi.Data.Sql.Dapper.MySql/YuckQi.Data.Sql.Dapper.MySql.csproj b/src/YuckQi.Data.Sql.Dapper.MySql/YuckQi.Data.Sql.Dapper.MySql.csproj index be4df30..cf61eaa 100644 --- a/src/YuckQi.Data.Sql.Dapper.MySql/YuckQi.Data.Sql.Dapper.MySql.csproj +++ b/src/YuckQi.Data.Sql.Dapper.MySql/YuckQi.Data.Sql.Dapper.MySql.csproj @@ -5,7 +5,7 @@ enable true Kevin J Lambert - 6.3.2 + 6.3.3 An implementation of YuckQi.Data for MySQL databases using Dapper and SimpleCRUD. YuckQi.Data https://github.com/Yuck/YuckQi.Data.git diff --git a/src/YuckQi.Data.Sql.Dapper.Oracle/YuckQi.Data.Sql.Dapper.Oracle.csproj b/src/YuckQi.Data.Sql.Dapper.Oracle/YuckQi.Data.Sql.Dapper.Oracle.csproj index 8afd322..1716f58 100644 --- a/src/YuckQi.Data.Sql.Dapper.Oracle/YuckQi.Data.Sql.Dapper.Oracle.csproj +++ b/src/YuckQi.Data.Sql.Dapper.Oracle/YuckQi.Data.Sql.Dapper.Oracle.csproj @@ -5,7 +5,7 @@ enable true Kevin J Lambert - 6.3.2 + 6.3.3 An implementation of YuckQi.Data for Oracle databases using Dapper and SimpleCRUD. YuckQi.Data https://github.com/Yuck/YuckQi.Data.git diff --git a/src/YuckQi.Data.Sql.Dapper.SqlServer/YuckQi.Data.Sql.Dapper.SqlServer.csproj b/src/YuckQi.Data.Sql.Dapper.SqlServer/YuckQi.Data.Sql.Dapper.SqlServer.csproj index 2faed38..ab7bff6 100644 --- a/src/YuckQi.Data.Sql.Dapper.SqlServer/YuckQi.Data.Sql.Dapper.SqlServer.csproj +++ b/src/YuckQi.Data.Sql.Dapper.SqlServer/YuckQi.Data.Sql.Dapper.SqlServer.csproj @@ -5,7 +5,7 @@ enable true Kevin J Lambert - 6.3.2 + 6.3.3 An implementation of YuckQi.Data for MSSQL databases using Dapper and SimpleCRUD. YuckQi.Data https://github.com/Yuck/YuckQi.Data.git diff --git a/src/YuckQi.Data.Sql.Dapper/YuckQi.Data.Sql.Dapper.csproj b/src/YuckQi.Data.Sql.Dapper/YuckQi.Data.Sql.Dapper.csproj index cc5f134..af44795 100644 --- a/src/YuckQi.Data.Sql.Dapper/YuckQi.Data.Sql.Dapper.csproj +++ b/src/YuckQi.Data.Sql.Dapper/YuckQi.Data.Sql.Dapper.csproj @@ -5,7 +5,7 @@ enable true Kevin J Lambert - 6.3.2 + 6.3.3 An implementation of YuckQi.Data for SQL databases using Dapper and SimpleCRUD. YuckQi.Data https://github.com/Yuck/YuckQi.Data.git diff --git a/src/YuckQi.Data.Sql.EntityFramework/YuckQi.Data.Sql.EntityFramework.csproj b/src/YuckQi.Data.Sql.EntityFramework/YuckQi.Data.Sql.EntityFramework.csproj index 3140cce..7fa8ea4 100644 --- a/src/YuckQi.Data.Sql.EntityFramework/YuckQi.Data.Sql.EntityFramework.csproj +++ b/src/YuckQi.Data.Sql.EntityFramework/YuckQi.Data.Sql.EntityFramework.csproj @@ -5,7 +5,7 @@ enable true Kevin J Lambert - 6.3.2 + 6.3.3 An implementation of YuckQi.Data for SQL databases using Entity Framework. YuckQi.Data https://github.com/Yuck/YuckQi.Data.git diff --git a/src/YuckQi.Data/YuckQi.Data.csproj b/src/YuckQi.Data/YuckQi.Data.csproj index d0e4f07..33571f6 100644 --- a/src/YuckQi.Data/YuckQi.Data.csproj +++ b/src/YuckQi.Data/YuckQi.Data.csproj @@ -5,7 +5,7 @@ enable true Kevin J Lambert - 6.3.2 + 6.3.3 A .NET library of lightweight data access handlers which can be used to compose repositories and domain services. https://github.com/Yuck/YuckQi.Data.git git