Closed armpogart closed 1 month ago
You should always apply an upper bound to the page size because your system will run out of memory when processing too large pages.
It won't if you're using a DataReader and streaming the response without buffering :smile:
You can write your own stream class that does that and hook it up in the Response object.
OK, I understand the limitation of running out of memory, but for the REST response:
1) It is very difficult to run out of memory (usually) 2) It's up to developer, I don't propose to change the default behavior, I propose to have way of disabling this limit at all.
At the end it was discussed many times here on github (under different issues) that the framework (yii) must not limit the developer, it can propose the right way to do something with its' defaults, but not limit him/her.
Currently I have very concise JSON objects in my response and I read 1000 row response without any problems and without increasing default php memory limit. And I can't say exactly yet how much more I will be able to read in one go. I'm using REST as backend for Android application which does it's job in seperate thread and it has no any limitation there either, and for now it is very much convenient for me to read the whole response from Android and not go page by page.
In my case: REST request is filtered and the response theoretically can't grow so much that I will hit any limit, so I don't see reason why I can't disable that limit on my own risk. (actually I can, but I don't think that using flow of code to disable it is the right way)
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSizeLimit' => [1],
]
]);
@mdmunir Your code is not the way of disabling pageSizeLimit
, it is just a workaround. As I said anything but false and two dimensional array will work. Your way of doing it is the worst in my opinion, as you may think, tha giving one value in array will at least set lowet limit, but it will ignore that value.
Now that some time has passed, is there a "best practice" for changing (not necessarily disabling) the default pagination values? I realize I can override the yii/rest/IndexAction and change the pagination attributes, but this seems like something that should be more a config change than an override.
Closing since there's no such limit anymore.
yii2 REST API uses
ActiveDataProvider
to fetch and show data. This class haspageSizeLimit
parameter which by default limit ourpageSize
to 50, so no matter how high is per-page (pageSizeParam
) query parameter, maximum 50 rows are returned.Is there any way to completely disable
pageSizeLimit
so that provider will show as many rows as we want by specifying per-page query parameter ordefaultPageSize
if not specified? SettingpageSizeLimit
to false forces to always returndefaultPageSize
rows no matter what we pass by per-page.Further investigation of source code showed, that setting
pageSizeLimit
to anything butfalse
or two-dimensional array works, because the code in that case completely ignorespageSizeLimit
link.Won't it be better if we have framework proposed way of doing it and not hack, e.g. specifying only lower limit, or setting it
true
or something to obviously take the query param? I can make pull request if we come up with the way of specifying it...