Skip to content

Counting query is running synchronously #30

@MateuszBogdan

Description

@MateuszBogdan

First of all thank you for this great library 👍

Now, for the issue:

Even though whole PrimeNG.TableFilter API is async in nature there is one synchronous call in extension method PrimengTableFilter. I am talking about dataSet.Count(); by the end of the function.

Getting out int variable from method is very convenient, but this is Sync over Async antipattern. If you go async you have to go all way through.

My recommended sulution would be (unfortunately it would break the API) instead of returning int it would return query (IQueryable) without paging applied, so caller could invoke CountAsync.

Or even better, split this method into two. First method returning right after tableFilterManager.GetResult() and another that applies paging.

example calling code would look like this:

var intermediateQuery = dbContext.Set<TInput>()
    .Select(projection)
    .PrimengTableFilterNoPaging(filter);
var count = await intermediateQuery.CountAsync();
var resultQuery = intermediateQuery
    PrimengTableFilterPaging(filter);
var resultData = await resultQuery.ToListAsync();
return new QueryResult<TProjected>(resultData, count);

or it still may be converted to out variable (method should output IQueryable instead of int:

IQueryable<TProjection> countingQuery;
var resultData= await dbContext.Set<TInput>()
    .Select(projection)
    .PrimengTableFilter(filter, out countingQuery)
    .ToListAsync();
var count = await countingQuery.CountAsync();
return new QueryResult<TProjected>(resultData, count);

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions