SAAS-624: Request to rest/media throws an exception if the data set is too large
Added offset and limit parameters to /rest/media index action.
This commit is contained in:
parent
df28b47b92
commit
62d6849d4e
|
@ -14,27 +14,31 @@ class Rest_MediaController extends Zend_Rest_Controller
|
|||
|
||||
public function indexAction()
|
||||
{
|
||||
$pager = CcFilesQuery::create()->paginate($page=1, $maxPerPage=50);
|
||||
$numPages = $pager->getLastPage();
|
||||
$totalFileCount = BaseCcFilesQuery::create()->count();
|
||||
|
||||
$nextPage = 1;
|
||||
// Check if offset and limit were sent with request.
|
||||
// Default limit to zero and offset to $totalFileCount
|
||||
$offset = $this->_getParam('offset', 0);
|
||||
$limit = $this->_getParam('limit', $totalFileCount);
|
||||
|
||||
while ($nextPage <= $numPages) {
|
||||
$pager = CcFilesQuery::create()->paginate($page=$nextPage, $maxPerPage=50);
|
||||
|
||||
$files = array();
|
||||
foreach($pager->getResults() as $file) {
|
||||
array_push($files, CcFiles::sanitizeResponse($file));
|
||||
}
|
||||
$this->getResponse()->appendBody(json_encode($files));
|
||||
unset($files);
|
||||
|
||||
$nextPage +=1;
|
||||
$query = CcFilesQuery::create()
|
||||
->filterByDbHidden(false)
|
||||
->filterByDbImportStatus(0)
|
||||
->setLimit($limit)
|
||||
->setOffset($offset);
|
||||
$queryCount = $query->count();
|
||||
$queryResult = $query->find();
|
||||
|
||||
$files_array = array();
|
||||
foreach ($queryResult as $file)
|
||||
{
|
||||
array_push($files_array, CcFiles::sanitizeResponse($file));
|
||||
}
|
||||
|
||||
|
||||
$this->getResponse()
|
||||
->setHttpResponseCode(200);
|
||||
->setHttpResponseCode(200)
|
||||
->setHeader('X-TOTAL-COUNT', $queryCount)
|
||||
->appendBody(json_encode($files_array));
|
||||
|
||||
/** TODO: Use this simpler code instead after we upgrade to Propel 1.7 (Airtime 2.6.x branch):
|
||||
$this->getResponse()
|
||||
|
|
Loading…
Reference in New Issue