-
Notifications
You must be signed in to change notification settings - Fork 350
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
Allow @odata.count to be written after enumeration. #2594
Comments
Hi @uffelauesen -- Thanks for the investigation and for the contribution! Note that, according to protocol, the count should be written before the values:
We allow the count to be approximate in order to account for the fact that the service may not accurately know the count until the end. If the response does not follow ordering conventions (streaming != true), then it is valid to write the count at the end. So, minimally, we need to update the PR to no write the count at the end if streaming=true. The question would be, do we throw an exception if streaming=true and the count is not present until the end, or do we just silently ignore the count if it wasn't specified until the end. It should be an error if the user requested the count and we don't provide it, but we can silently ignore if the count was just being provided as additional metadata. |
Hi @mikepizzo I see, thanks for the description. It is actually when streaming=true, that I would have liked to be able to write the $count after the values. The implementation I have uses server driven paging, so clients will not be able to use the $count to detect how much data will be sent in the values collection as the server potentially cuts the results and delivers the nextLink. I have been using the $count=true feature to let the clients know the total amount of entities in a collection even if it has been truncated/paged. This information can be used by clients to show to the total count in a list together with a "next" button. The performance penalty is not so much of an issue for the root collection, but for expanded collections (like TripPin: Maybe you could consider something like this to be added to a coming revision of the V4 protocol. For now I will either de-support $count=true or supply the count value as a custom resource set annotation if possible. Thanks for the feedback. |
Hi @mikepizzo I will think about your suggestions some more and see if we can get something aligned. I spent the day trying to get the count written after values in a custom annotation. It is possible, but clients would need to add the annotations writing in Prefer header. I also noticed that missing counts are silently ignored even if requested by client as it is now (before my PR changes). If this current behaviour is valid - then I can’t see why it should not be allowed to write it at the end. I have to think about this a bit more. Uffe |
It is not allowed to write custom annotations on expanded resource sets neither before or after the values. |
In ODataJsonLightWriter.cs @odata.count annotations are written before enumeration of the resource set in StartResourceSetAsync or StartDeltaResourceSetAsync. This forces us to get the count calculated before we fetch data. In the implementation I have, this will require issuing a "select count() from..." query on my DB before the actual data query is issued "select a, b from...". In cases where all items in a resource set is returned in the payload we could avoid the "select count() from..." query as we already know the total number items.
@odata.nextLink annotation already behaves this way. It is either written early (before enumeration), if it set early in the resource set or after enumeration if it set later.
As far as I can read in the spec on odata.org, there is no mention of whether or not @odata.count should come early in the payload, so...
For performance reasons, please allow @odata.count annotations to be written in EndResourceSetAsync if not already written in StartResourceSetAsync or StartDeltaResourceSetAsync, like it is already possible with @odata.nextLink.
Assemblies affected
OData .Net lib 7.x
The text was updated successfully, but these errors were encountered: