Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: default spec does not return all results and defaults to 25 #400

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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 @@ -26,7 +26,7 @@ public async ValueTask<TResult> QueryAsync<TResult>(
IQueryable<TItem> query = container
.GetItemLinqQueryable<TItem>(
requestOptions: options,
continuationToken: specification.ContinuationToken,
continuationToken: specification.ContinuationToken,
linqSerializerOptions: optionsMonitor.CurrentValue.SerializationOptions)
.Where(repositoryExpressionProvider.Default<TItem>());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,15 @@ private static void TryLogDebugDetails(ILogger logger, Func<string> getMessage)
{
string? continuationToken = null;
List<TItem> results = [];
var readItemsCount = 0;
double charge = 0;
using var iterator = query.ToFeedIterator();
while (readItemsCount < pageSize && iterator.HasMoreResults)
while (results.Count != pageSize && iterator.HasMoreResults)
{
FeedResponse<TItem> next =
await iterator.ReadNextAsync(cancellationToken)
.ConfigureAwait(false);

foreach (TItem result in next)
{
if (readItemsCount == pageSize)
{
break;
}

results.Add(result);
readItemsCount++;
}
results = results.Concat(pageSize > 0 ? next.Take(pageSize) : next).ToList();

charge += next.RequestCharge;
continuationToken = next.ContinuationToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ namespace Microsoft.Azure.CosmosRepository.Specification;
public class DefaultSpecification<TItem> : BaseSpecification<TItem, IQueryResult<TItem>>
where TItem : IItem
{
public DefaultSpecification()
{
PageSize = -1;
}

/// <inheritdoc/>
public override IQueryResult<TItem> PostProcessingAction(
IReadOnlyList<TItem> queryResult,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public IQueryable<TItem> GetQuery<TItem, TResult>(
return query;
}

if (specification.PageSize < 0)
{
return query;
}

if (specification.PageNumber.HasValue && specification.PageNumber != 0)
{
query = query.Skip(specification.PageSize * (specification.PageNumber.Value - 1));
Expand Down
Loading