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

Check MaxPageSize before using PageSize throughout the code #12269

Closed
MikeAlhayek opened this issue Aug 26, 2022 · 7 comments · Fixed by #12270
Closed

Check MaxPageSize before using PageSize throughout the code #12269

MikeAlhayek opened this issue Aug 26, 2022 · 7 comments · Fixed by #12270
Milestone

Comments

@MikeAlhayek
Copy link
Member

Describe the bug

The only place we check against MaxPageSize in on OC.Contents.AdminController

The logic should be

if (_pagerOptions.MaxPageSize > 0 && pager.PageSize > _pagerOptions.MaxPageSize)
{
    pager.PageSize = _pagerOptions.MaxPagedCount;
}

I suggest we create GetPageSize() method that looks like this and use irt instead of using PageSize property

    public int GetPageSize()
    {
        if (MaxPageSize > 0 && PageSize > MaxPageSize)
        {
            return MaxPageSize;
        }

        return PageSize > 0 ? PageSize : DefaultPageSize;
    }

Also, something went wrong with recent merge where these 2 code blocks were added instead of replacing the second block

image

@jtkech
Copy link
Member

jtkech commented Aug 26, 2022

So, MaxPageSize limit the number of items per page, and MaxPagedCount limit the total number of items we query. But as I understand the previous code, MaxPagedCount was also used to limit MaxPageSize, to not specify a number per page > total items count, unless we assume that MaxPageSize is always less than MaxPagedCount, but they are settings that can be updated and where 0 means don't use it.

So maybe MaxPagedCount should still be also used to limit MaxPageSize, it should if we want to keep the previous behavior.

@MikeAlhayek
Copy link
Member Author

@jtkech Why would we want to check MaxPagedCount to determine the PageSize? MaxPagedCount is only to limit the total records coming from the database. I don’t think it should have to do with determining the page size

@jtkech
Copy link
Member

jtkech commented Aug 26, 2022

Because we init the pager TotalItemCount (here the pager shape) with it and we don't want an use case with the pager PageSize being higher than the pager shape TotalItemCount.

@MikeAlhayek
Copy link
Member Author

MikeAlhayek commented Aug 26, 2022

@jtkech I get that, but in that case we just render all the items on 1 page. Are you saying having TotalItemCount higher values that PageSize will cause issue?

@jtkech
Copy link
Member

jtkech commented Aug 26, 2022

Yes I think you're right, in that case it will render a List of items without the pager.

Are you saying having TotalItemCount higher values that PageSize will cause issue?

No because this is in that case that the pager is used.

So looks good but maybe check what the pagerShape code does with pagerSize and TotalItemCount.

@MikeAlhayek
Copy link
Member Author

Yes I already checked.

var totalPageCount = pageSize > 0 ? (int)Math.Ceiling(TotalItemCount / pageSize) : 1;
It returns 1 so checking MaxPagedCount is not needed

@jtkech
Copy link
Member

jtkech commented Aug 26, 2022

Okay cool then

@sebastienros sebastienros added this to the 1.x milestone Sep 1, 2022
@Skrypt Skrypt modified the milestones: 1.x, 1.5 Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants