-
Notifications
You must be signed in to change notification settings - Fork 172
Fix/Improve TruncatedCollectionOfT #1492
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?
Conversation
|
||
bool isTruncated = false; | ||
int count = 0; | ||
await foreach (var item in source.Take(checked(capacity + 1)).WithCancellation(cancellationToken).ConfigureAwait(false)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite understand. Isn't it strange to enumerate an IAsyncENumerable to put it in a list and then put it back in a new IAsyncEnumerable?
Shouldn't we stream the data completely? From what I understood, the only real problem is that the count was accessed at the beginning, but this is no longer the case since #1393
Shouldn't we introduce a TrucatedEnumerable instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @rpallares for pointing this out. I have updated it. Could you take another look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors TruncatedCollection<T>
to use composition instead of inheriting from List<T>
, adds support for asynchronous truncation via IAsyncEnumerable<T>
, and introduces corresponding static Create
methods and tests.
- Refactored
TruncatedCollection<T>
to implementIReadOnlyList<T>
andIAsyncEnumerable<T>
, with internal factory methods - Introduced
TruncatedAsyncEnumerable<T>
andTruncationState
to support async enumeration and truncation tracking - Expanded unit tests to cover the new sync, queryable, and async creation methods
- Updated project file to include
System.Linq.AsyncEnumerable
package for async LINQ extensions
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
test/.../TruncatedCollectionOfTTest.cs | Added tests for Create overloads (sync, queryable, async) |
src/.../Query/Container/TruncatedCollectionOfT.cs | Refactored class to use composition, added async support |
src/.../Query/Container/TruncatedAsyncEnumerableOfT.cs | New async enumerable type for truncation |
src/Microsoft.AspNetCore.OData/Microsoft.AspNetCore.OData.csproj | Added reference to System.Linq.AsyncEnumerable preview package |
Comments suppressed due to low confidence (2)
test/Microsoft.AspNetCore.OData.Tests/Query/Container/TruncatedCollectionOfTTest.cs:55
- [nitpick] Test method naming is inconsistent with the existing
CtorTruncatedCollection_SetsProperties
pattern. Consider standardizing on aCreate_*_SetsProperties
orCtor_*_SetsProperties
convention for clarity.
public void TruncatedCollectionCreateForIEnumerable_SetsProperties()
src/Microsoft.AspNetCore.OData/Query/Container/TruncatedCollectionOfT.cs:189
- The XML doc comment has a duplicated
/// ///
. It should be corrected to a single/// <param...>
for proper tooling support.
/// /// <param name="totalCount">The total count. Default null.</param>
src/Microsoft.AspNetCore.OData/Query/Container/TruncatedCollectionOfT.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.AspNetCore.OData/Query/Container/TruncatedCollectionOfT.cs
Outdated
Show resolved
Hide resolved
…tionOfT.cs Co-authored-by: Copilot <[email protected]>
…OData/AspNetCoreOData into fix/improve-truncatedcollection
/// <summary> | ||
/// Used to track the truncation state of an async enumerable. | ||
/// </summary> | ||
public class TruncationState |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why have this a separate class instead of a boolean field of the TruncatedAsyncEnumerable
class?
No description provided.