-
-
Notifications
You must be signed in to change notification settings - Fork 102
Feature/support continuation token limit property #437
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,10 @@ | |
|
|
||
|
|
||
| // ReSharper disable once CheckNamespace | ||
| using System.Threading; | ||
| using Microsoft.Azure.Cosmos; | ||
| using Microsoft.Extensions.Options; | ||
|
|
||
| namespace Microsoft.Azure.CosmosRepository; | ||
|
|
||
| internal sealed partial class DefaultRepository<TItem> | ||
|
|
@@ -13,19 +17,36 @@ public async ValueTask<IPage<TItem>> PageAsync( | |
| int pageSize = 25, | ||
| string? continuationToken = null, | ||
| bool returnTotal = false, | ||
| CancellationToken cancellationToken = default) | ||
| { | ||
| CancellationToken cancellationToken = default) | ||
| => await PageAsync( | ||
victormarante marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| new QueryRequestOptions() { MaxItemCount = pageSize }, | ||
victormarante marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| predicate, | ||
| pageSize, | ||
| continuationToken, | ||
| returnTotal, | ||
| cancellationToken); | ||
|
|
||
| /// <inheritdoc/> | ||
| public async ValueTask<IPage<TItem>> PageAsync( | ||
| QueryRequestOptions requestOptions, | ||
| Expression<Func<TItem, bool>>? predicate = null, | ||
| int pageSize = 25, | ||
| string? continuationToken = null, | ||
| bool returnTotal = false, | ||
| CancellationToken cancellationToken = default) | ||
| { | ||
| Container container = await containerProvider.GetContainerAsync() | ||
| .ConfigureAwait(false); | ||
|
|
||
| QueryRequestOptions options = new() | ||
| { | ||
| MaxItemCount = pageSize | ||
| }; | ||
| .ConfigureAwait(false); | ||
|
|
||
| // make sure that if the user hasn't said the value already we take it from the pageSize parameter | ||
| if (requestOptions.MaxItemCount is null) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You must expect that null could be passed. Initialize requestOptions if the value is null.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or throw exception
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By default, I don't trust users 😂 But if for you it's ok then for me too 😄 |
||
| { | ||
| requestOptions.MaxItemCount = pageSize; | ||
| } | ||
|
|
||
| IQueryable<TItem> query = container | ||
| .GetItemLinqQueryable<TItem>( | ||
| requestOptions: options, | ||
| requestOptions: requestOptions, | ||
| continuationToken: continuationToken, | ||
| linqSerializerOptions: optionsMonitor.CurrentValue.SerializationOptions) | ||
| .Where(repositoryExpressionProvider.Build( | ||
|
|
@@ -51,7 +72,7 @@ public async ValueTask<IPage<TItem>> PageAsync( | |
| pageSize, | ||
| items.AsReadOnly(), | ||
| charge + countResponse?.RequestCharge ?? 0, | ||
| resultingContinuationToken); | ||
| resultingContinuationToken); | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
|
|
@@ -61,13 +82,30 @@ public async ValueTask<IPageQueryResult<TItem>> PageAsync( | |
| int pageSize = 25, | ||
| bool returnTotal = false, | ||
| CancellationToken cancellationToken = default) | ||
| { | ||
| => await PageAsync( | ||
| requestOptions: new QueryRequestOptions() { MaxItemCount = pageSize }, | ||
victormarante marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| predicate: predicate, | ||
| pageNumber: pageNumber, | ||
| pageSize: pageSize, | ||
| returnTotal: returnTotal, | ||
| cancellationToken: cancellationToken); | ||
|
|
||
| /// <inheritdoc/> | ||
| public async ValueTask<IPageQueryResult<TItem>> PageAsync( | ||
| QueryRequestOptions requestOptions, | ||
| Expression<Func<TItem, bool>>? predicate = null, | ||
| int pageNumber = 1, | ||
| int pageSize = 25, | ||
| bool returnTotal = false, | ||
| CancellationToken cancellationToken = default) | ||
| { | ||
| Container container = await containerProvider.GetContainerAsync() | ||
| .ConfigureAwait(false); | ||
|
|
||
| IQueryable<TItem> query = container | ||
| .GetItemLinqQueryable<TItem>( | ||
| linqSerializerOptions: optionsMonitor.CurrentValue.SerializationOptions) | ||
| linqSerializerOptions: optionsMonitor.CurrentValue.SerializationOptions, | ||
| requestOptions: requestOptions) | ||
| .Where(repositoryExpressionProvider | ||
| .Build(predicate ?? repositoryExpressionProvider.Default<TItem>())); | ||
|
|
||
|
|
@@ -94,6 +132,6 @@ public async ValueTask<IPageQueryResult<TItem>> PageAsync( | |
| pageSize, | ||
| items.AsReadOnly(), | ||
| charge + countResponse?.RequestCharge ?? 0, | ||
| resultingContinuationToken /* This was missing, is this correct? */); | ||
| resultingContinuationToken /* This was missing, is this correct? */); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.