From c3fa374f252b72b4ed545fbcdec159324268ca38 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Tue, 19 May 2026 21:45:20 +0200 Subject: [PATCH] Fix empty entry Generator (#8863) * Fix empty entry Generator Fix https://github.com/FreshRSS/FreshRSS/issues/8857 Regression from https://github.com/FreshRSS/FreshRSS/pull/8789 This is due to https://bugs.php.net/bug.php?id=77515 * Use EmptyIterator instead * Syntax update --- app/Controllers/indexController.php | 21 ++++++++++++--------- p/api/query.php | 4 +++- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php index 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.php index 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 exports FreshRSS_Context::$search = $userSearch; // Restore user search for display and exports } catch (Minz_Exception) {