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

Set capacity for TruncatedCollection(IQueryable, int, boolean) overload #1183

Merged
2 changes: 1 addition & 1 deletion sample/BenchmarkServer/Controllers/ProductsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public ProductsController(ProductsContext context)
}

[HttpGet]
[EnableQuery]
[EnableQuery(PageSize = 3000)]
public IActionResult Get()
{
return Ok(products);
Expand Down
senioroman4uk marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ public class TruncatedCollection<T> : List<T>, ITruncatedCollection, IEnumerable
/// <param name="source">The collection to be truncated.</param>
/// <param name="pageSize">The page size.</param>
public TruncatedCollection(IEnumerable<T> source, int pageSize)
: base(source.Take(checked(pageSize + 1)))
: base(checked(pageSize + 1))
{
var items = source.Take(checked(pageSize + 1));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to do something like this to avoid the same calculation again (and opening it up for potential inconsistencies in the future)?

Suggested change
var items = source.Take(checked(pageSize + 1));
var items = source.Take(Capacity);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, applied

AddRange(items);
Initialize(pageSize);
}

Expand All @@ -54,8 +56,10 @@ public TruncatedCollection(IQueryable<T> source, int pageSize) : this(source, pa
// NOTE: The queryable version calls Queryable.Take which actually gets translated to the backend query where as
// the enumerable version just enumerates and is inefficient.
public TruncatedCollection(IQueryable<T> source, int pageSize, bool parameterize)
: base(Take(source, pageSize, parameterize))
: base(checked(pageSize + 1))
senioroman4uk marked this conversation as resolved.
Show resolved Hide resolved
{
var items = Take(source, pageSize, parameterize);
AddRange(items);
Initialize(pageSize);
}

Expand Down