Open Closed

Saas Module tenant GetCountAsync() filtering issue ? #3215


User avatar
0
selinkoykiran created

Hello , we want to filter /api/saas/tenants with ActivationState parameter , but total count parameter returns wrongly from backend . We've checked from the module code : Why doesn't count method use the same filtering with the GetListAsync () method ?

Why do you use only EditionId and name filtering for GetCountAsync() ? Is there any reason or is it forgotten ?

Thank you.

  • ABP Framework version: v5.1.1
  • UI type: MVC
  • DB provider: EF Core
  • **Tiered (MVC) : yes
  • Exception message and stack trace:
  • Steps to reproduce the issue:"

3 Answer(s)
  • User Avatar
    0
    gterdem created
    Senior .NET Developer

    Hello,

    Well, we can discuss it.

    If you would filter the count like getting a list, why make another DB request to get the count instead of getting the count of the list that you already got.

    Lets consider the application service:

    public virtual async Task<PagedResultDto<SaasTenantDto>> GetListAsync(GetTenantsInput input)
        {
            var count = await TenantRepository.GetCountAsync(input.Filter, input.EditionId);
            var tenantList = await TenantRepository.GetListAsync(
                input.Sorting,
                input.MaxResultCount,
                input.SkipCount,
                input.Filter,
                includeDetails: true,
                input.EditionId,
                input.ExpirationDateMin,
                input.ExpirationDateMax,
                input.ActivationState
            );
        ...
        
            return new PagedResultDto<SaasTenantDto>(
                count,
                tenantDtos
            );
        }
    

    Generally, application services return a PagedResultDto to allow pagination. If you require the count of filtered data, you can always get the count of the tenantList.

    You can argue that the GetCountAsync repository method can be used in domain services for some business-related logic for performance but It can be wrongly used and It will be a breaking change.

    I would suggest overriding this method for your business needs is better than trying to figure out why the count is wrong while finding out a junior developer passes the same parameters to GetCountAsync method as in GetListAsync method :)

  • User Avatar
    0
    selinkoykiran created

    Hello, Actually, yes we can override easily :) We don't do another request like you mentioned :) For example:

    In this example, we are filtering the tenants just with activation state , it returns 1 record (which is true in our case , because we have only 1 record with that activation state in the db) , because of the total count which is 3 (because of GetCountAsync() filtering issue) , our datatable's and paging is just going crazy.

    So , we can override of course , but what do you think about this specific example ? Is it right when you have paging and you're filtering the records you have totally 3 records from the count but the real count is 1 so you are expecting 2 more records because max count is 10 ? What do you think ?

  • User Avatar
    0
    gterdem created
    Senior .NET Developer

    Hello,

    We have discussed this internally. Your case is valid and our other modules follow the same rules. Pagination is wrong if we do not supply filtered data. Unfiltered data can be received without parameters anyway. So, we decided this is a bug and needs to be fixed.

    I have created an internal issue for this and this will be fixed in the next release.

    Thank you for your report!

Made with ❤️ on ABP v9.1.0-preview. Updated on December 12, 2024, 07:15