You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
A user can do the following code. This is very bad because it is doing a synchronous read feed. IQueryable.Where does not support taking in a func. Only the IEnumerable.Where supports func. This will cause the SDK will read all the items from the container so it returns an IEnumerable. The IEnumerable.Where then can be ran over all the items on the client side. This very inefficient and consume a lot of RUs.
List<Family> families = new List<Family>();
Func<Family, bool> v = new Func<Family, bool>(x => true);
// SQL
IEnumerable<Family> setIterator = container.GetItemLinqQueryable<Family>(true).Where(v).AsEnumerable<Family>();
foreach (Family item in setIterator)
{
families.Add(item);
}
Assert("Expected two families", families.ToList().Count == 2);
The user should pass in an expression rather than a function. The expression can be parsed into a SQL query. This means all the filtering is done on Cosmos DB and only the required items are returned. The code should also be run asynchronously to avoid performance issue once the application starts to scale.
There are 2 solutions I see that can help prevent other users from hitting this.
Add a request option that has to be enabled to support sync read feed.
Implement a custom ICosmosQueryable that is almost identical to the current IQueryable. The big difference is we can have an explicit ExecuteAsync to actually run the query. This would also allow the ability to support CountAsync and other aggregates.
The text was updated successfully, but these errors were encountered:
Describe the bug
A user can do the following code. This is very bad because it is doing a synchronous read feed. IQueryable.Where does not support taking in a func. Only the IEnumerable.Where supports func. This will cause the SDK will read all the items from the container so it returns an IEnumerable. The IEnumerable.Where then can be ran over all the items on the client side. This very inefficient and consume a lot of RUs.
The user should pass in an expression rather than a function. The expression can be parsed into a SQL query. This means all the filtering is done on Cosmos DB and only the required items are returned. The code should also be run asynchronously to avoid performance issue once the application starts to scale.
There are 2 solutions I see that can help prevent other users from hitting this.
The text was updated successfully, but these errors were encountered: