A free, self-hostable news aggregator…
Fix empty entry Generator (#8863)
Alexandre Alapetitec3fa374f252b
diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.phpindex b80f65fd0..50cfefaa6 100644--- a/app/Controllers/indexController.php+++ b/app/Controllers/indexController.php@@ -173,6 +173,9 @@ class FreshRSS_index_Controller extends FreshRSS_ActionController {try {// +1 to account for paging logic$view->entries = FreshRSS_index_Controller::listEntriesByContext(FreshRSS_Context::$number + 1);+ if (!$view->entries->valid()) { // Init the generator to catch potential exceptions+ $view->entries = new EmptyIterator();+ }ob_start(); //Buffer "one entry at a time"} catch (FreshRSS_EntriesGetter_Exception $e) {Minz_Log::notice($e->getMessage());@@ -258,7 +261,9 @@ class FreshRSS_index_Controller extends FreshRSS_ActionController {try {$this->view->entries = FreshRSS_index_Controller::listEntriesByContext();- $this->view->entries->current(); // Init the generator to catch potential exceptions+ if (!$this->view->entries->valid()) { // Init the generator to catch potential exceptions+ $this->view->entries = new EmptyIterator();+ }} catch (FreshRSS_EntriesGetter_Exception $e) {Minz_Log::notice($e->getMessage());Minz_Error::error(404);@@ -397,14 +402,12 @@ class FreshRSS_index_Controller extends FreshRSS_ActionController {}}- foreach ($entryDAO->listWhere(- $type, $id, FreshRSS_Context::$state, FreshRSS_Context::$search,- id_min: $id_min, id_max: FreshRSS_Context::$id_max, sort: FreshRSS_Context::$sort, order: FreshRSS_Context::$order,- continuation_id: FreshRSS_Context::$continuation_id, continuation_values: $continuation_values,- limit: $postsPerPage ?? FreshRSS_Context::$number, offset: FreshRSS_Context::$offset,- secondary_sort: FreshRSS_Context::$secondary_sort, secondary_sort_order: FreshRSS_Context::$secondary_sort_order) as $entry) {- yield $entry;- }+ yield from $entryDAO->listWhere(+ $type, $id, FreshRSS_Context::$state, FreshRSS_Context::$search,+ id_min: $id_min, id_max: FreshRSS_Context::$id_max, sort: FreshRSS_Context::$sort, order: FreshRSS_Context::$order,+ continuation_id: FreshRSS_Context::$continuation_id, continuation_values: $continuation_values,+ limit: $postsPerPage ?? FreshRSS_Context::$number, offset: FreshRSS_Context::$offset,+ secondary_sort: FreshRSS_Context::$secondary_sort, secondary_sort_order: FreshRSS_Context::$secondary_sort_order);}/**diff --git a/p/api/query.php b/p/api/query.phpindex 63bc43532..2d92800b9 100644--- a/p/api/query.php+++ b/p/api/query.php@@ -118,7 +118,9 @@ $view = new FreshRSS_View();try {FreshRSS_Context::updateUsingRequest(false);$view->entries = FreshRSS_index_Controller::listEntriesByContext();- $view->entries->current(); // Init the generator to consume the aggregated search and catch potential exceptions+ if (!$view->entries->valid()) { // Init the generator to consume the aggregated search and catch potential exceptions+ $view->entries = new EmptyIterator();+ }Minz_Request::_param('search', $userSearch->toString()); // Restore user search for display and exportsFreshRSS_Context::$search = $userSearch; // Restore user search for display and exports} catch (Minz_Exception) {