Skip to content

Commit

Permalink
#13 - DynamoDB RetrievalHandler GetList should be using Query and not…
Browse files Browse the repository at this point in the history
… Scan (closes #13)
  • Loading branch information
Yuck committed Aug 3, 2023
1 parent bad57b3 commit b16f057
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 22 deletions.
35 changes: 22 additions & 13 deletions src/YuckQi.Data.DocumentDb.DynamoDb/Handlers/RetrievalHandler.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -80,9 +75,8 @@ public RetrievalHandler(Func<TIdentifier, Primitive> hashKeyValueFactory, Func<T
var table = scope.GetTargetTable<TDocument>();
var filter = parameters.ToQueryFilter();
var search = table.Query(filter);
var results = await search.GetRemainingAsync(cancellationToken);
var result = results.SingleOrDefault();
var document = scope.FromDocument<TDocument>(result);
var documents = await GetDocuments(scope, search, cancellationToken);
var document = documents.SingleOrDefault();
var entity = MapToEntity(document);

return entity;
Expand All @@ -105,12 +99,27 @@ protected override async Task<IReadOnlyCollection<TEntity>> DoGetList(IReadOnlyC
throw new ArgumentNullException(nameof(scope));

var table = scope.GetTargetTable<TDocument>();
var filter = parameters?.ToScanFilter();
var search = table.Scan(filter);
var results = await search.GetRemainingAsync(cancellationToken);
var documents = scope.FromDocuments<TDocument>(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<IEnumerable<TDocument>> 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<Document>();

while (! search.IsDone)
documents.AddRange(await search.GetNextSetAsync(cancellationToken));
documents.AddRange(await search.GetRemainingAsync(cancellationToken));

return scope.FromDocuments<TDocument>(documents);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.3.2</Version>
<Version>6.3.3</Version>
<Description>An implementation of YuckQi.Data for Amazon DynamoDB databases.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.3.2</Version>
<Version>6.3.3</Version>
<Description>An implementation of YuckQi.Data for MongoDB databases.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
2 changes: 1 addition & 1 deletion src/YuckQi.Data.MemDb/YuckQi.Data.MemDb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.3.2</Version>
<Version>6.3.3</Version>
<Description>An implementation of YuckQi.Data for a in-memory "database" (ConcurrentDictionary), ideal for rapid development without external dependencies.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.3.2</Version>
<Version>6.3.3</Version>
<Description>An implementation of YuckQi.Data for MySQL databases using Dapper and SimpleCRUD.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.3.2</Version>
<Version>6.3.3</Version>
<Description>An implementation of YuckQi.Data for Oracle databases using Dapper and SimpleCRUD.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.3.2</Version>
<Version>6.3.3</Version>
<Description>An implementation of YuckQi.Data for MSSQL databases using Dapper and SimpleCRUD.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
2 changes: 1 addition & 1 deletion src/YuckQi.Data.Sql.Dapper/YuckQi.Data.Sql.Dapper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.3.2</Version>
<Version>6.3.3</Version>
<Description>An implementation of YuckQi.Data for SQL databases using Dapper and SimpleCRUD.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.3.2</Version>
<Version>6.3.3</Version>
<Description>An implementation of YuckQi.Data for SQL databases using Entity Framework.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
2 changes: 1 addition & 1 deletion src/YuckQi.Data/YuckQi.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.3.2</Version>
<Version>6.3.3</Version>
<Description>A .NET library of lightweight data access handlers which can be used to compose repositories and domain services.</Description>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand Down

0 comments on commit b16f057

Please sign in to comment.