From df28b47b925032b09227b546c77789ea0d22219b Mon Sep 17 00:00:00 2001 From: drigato Date: Wed, 4 Mar 2015 16:26:35 -0500 Subject: [PATCH 1/4] SAAS-624: Request to rest/media throws an exception if the data set is too large --- .../rest/controllers/MediaController.php | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/airtime_mvc/application/modules/rest/controllers/MediaController.php b/airtime_mvc/application/modules/rest/controllers/MediaController.php index acb0eeed7..c2f140666 100644 --- a/airtime_mvc/application/modules/rest/controllers/MediaController.php +++ b/airtime_mvc/application/modules/rest/controllers/MediaController.php @@ -14,15 +14,27 @@ class Rest_MediaController extends Zend_Rest_Controller public function indexAction() { - $files_array = array(); - foreach (CcFilesQuery::create()->find() as $file) - { - array_push($files_array, CcFiles::sanitizeResponse($file)); + $pager = CcFilesQuery::create()->paginate($page=1, $maxPerPage=50); + $numPages = $pager->getLastPage(); + + $nextPage = 1; + + 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; + } $this->getResponse() - ->setHttpResponseCode(200) - ->appendBody(json_encode($files_array)); + ->setHttpResponseCode(200); /** TODO: Use this simpler code instead after we upgrade to Propel 1.7 (Airtime 2.6.x branch): $this->getResponse() From 62d6849d4e71062f6149aeb69de4e34f3a4d0928 Mon Sep 17 00:00:00 2001 From: drigato Date: Thu, 5 Mar 2015 14:25:48 -0500 Subject: [PATCH 2/4] 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. --- .../rest/controllers/MediaController.php | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/airtime_mvc/application/modules/rest/controllers/MediaController.php b/airtime_mvc/application/modules/rest/controllers/MediaController.php index c2f140666..6a116c13f 100644 --- a/airtime_mvc/application/modules/rest/controllers/MediaController.php +++ b/airtime_mvc/application/modules/rest/controllers/MediaController.php @@ -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() From 962f5d925d187a3bfaae4e96f7a62733559627d0 Mon Sep 17 00:00:00 2001 From: drigato Date: Fri, 6 Mar 2015 09:32:14 -0500 Subject: [PATCH 3/4] SAAS-624: Request to rest/media throws an exception if the data set is too large Fixed small typo --- .../application/modules/rest/controllers/MediaController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airtime_mvc/application/modules/rest/controllers/MediaController.php b/airtime_mvc/application/modules/rest/controllers/MediaController.php index 6a116c13f..5f41162ef 100644 --- a/airtime_mvc/application/modules/rest/controllers/MediaController.php +++ b/airtime_mvc/application/modules/rest/controllers/MediaController.php @@ -14,7 +14,7 @@ class Rest_MediaController extends Zend_Rest_Controller public function indexAction() { - $totalFileCount = BaseCcFilesQuery::create()->count(); + $totalFileCount = CcFilesQuery::create()->count(); // Check if offset and limit were sent with request. // Default limit to zero and offset to $totalFileCount From e315498a5cdeebb58aa0e3c929dd469f8edb071f Mon Sep 17 00:00:00 2001 From: drigato Date: Fri, 6 Mar 2015 12:21:51 -0500 Subject: [PATCH 4/4] SAAS-624: Request to rest/media throws an exception if the data set is too large Modified /rest/media to return items where file_exists = true --- .../application/modules/rest/controllers/MediaController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/airtime_mvc/application/modules/rest/controllers/MediaController.php b/airtime_mvc/application/modules/rest/controllers/MediaController.php index 5f41162ef..44d037e83 100644 --- a/airtime_mvc/application/modules/rest/controllers/MediaController.php +++ b/airtime_mvc/application/modules/rest/controllers/MediaController.php @@ -23,6 +23,7 @@ class Rest_MediaController extends Zend_Rest_Controller $query = CcFilesQuery::create() ->filterByDbHidden(false) + ->filterByDbFileExists(true) ->filterByDbImportStatus(0) ->setLimit($limit) ->setOffset($offset);