Skip to content

Using CancellationTokens to cancel long running queries #1788

Open
@henning-krause

Description

@henning-krause

In the "standard" WebAPI I can add a CancellationToken to a controler and the infrastructure cancels the token when a client disconnects:

    [HttpGet("/slowtest")]
    public async Task<string> Get(CancellationToken cancellationToken) {}

In an OData controller this doesn't makes sense in most cases (when I just return an IQueryable).

However, could the OData Framework somehow implement this internally?

I'm in the situation where I query 100 elements from several million records. The query itself ist fast (50ms) , but the IncludeTotalCount option makes the call very slow (5 seconds). I've already separated the first call from the second so that the users get the items very fast and the number of items later. But if I page through the results fast, multiple Count() operations accumulate up. It would be nice if I could cancel the queries somehow.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions