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

Counting query is running synchronously #30

Open
MateuszBogdan opened this issue Jul 29, 2022 · 0 comments
Open

Counting query is running synchronously #30

MateuszBogdan opened this issue Jul 29, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@MateuszBogdan
Copy link

MateuszBogdan commented Jul 29, 2022

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);
@Kusumoto Kusumoto added the enhancement New feature or request label Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants