From 0f94402b7e8b7e25ee605f830b7c7becbe78ba8b Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 29 Feb 2020 18:19:09 +0100 Subject: Better performance with yield (#2588) * Better performance with yield Largely decrease the time to first byte, and reduced memory consumtion. Before, we used to make several copies in memory of the whole list of articles before sending them to the client. Now streamed as they are processed. * Travis --- app/views/index/normal.phtml | 51 +++++++++++++++++++++++++++----------------- app/views/index/reader.phtml | 39 ++++++++++++++++++++++----------- 2 files changed, 58 insertions(+), 32 deletions(-) (limited to 'app/views/index') diff --git a/app/views/index/normal.phtml b/app/views/index/normal.phtml index 23105df5c..50574ee4d 100644 --- a/app/views/index/normal.phtml +++ b/app/views/index/normal.phtml @@ -3,22 +3,32 @@ $this->partial('aside_feed'); $this->partial('nav_menu'); -if (!empty($this->entries)) { - $display_today = true; - $display_yesterday = true; - $display_others = true; - $hidePosts = !FreshRSS_Context::$user_conf->display_posts; - $lazyload = FreshRSS_Context::$user_conf->lazyload; - $content_width = FreshRSS_Context::$user_conf->content_width; +call_user_func($this->callbackBeforeEntries, $this); - $today = @strtotime('today'); +$display_today = true; +$display_yesterday = true; +$display_others = true; +$hidePosts = !FreshRSS_Context::$user_conf->display_posts; +$lazyload = FreshRSS_Context::$user_conf->lazyload; +$content_width = FreshRSS_Context::$user_conf->content_width; + +$today = @strtotime('today'); ?> -
+
+
entries as $item) { + $firstEntry = null; + $lastEntry = null; + $nbEntries = 0; + foreach ($this->entries as $item): + if ($nbEntries === 0) { + $firstEntry = $item; + } + $lastEntry = $item; + $nbEntries++; + ob_flush(); $this->entry = Minz_ExtensionManager::callHook('entry_before_display', $item); if ($this->entry == null) { continue; @@ -87,16 +97,19 @@ if (!empty($this->entries)) { ?>
renderHelper('pagination'); -?>
+ endforeach; -show_nav_buttons) $this->partial('nav_entries'); ?> - - + if ($nbEntries > 0): + call_user_func($this->callbackBeforePagination, $this, $nbEntries, $firstEntry, $lastEntry); + $this->renderHelper('pagination'); +?>



- + + + 0 && FreshRSS_Context::$user_conf->show_nav_buttons) $this->partial('nav_entries'); ?> diff --git a/app/views/index/reader.phtml b/app/views/index/reader.phtml index e935db4a8..ee9e19327 100644 --- a/app/views/index/reader.phtml +++ b/app/views/index/reader.phtml @@ -2,18 +2,28 @@ $this->partial('aside_feed'); $this->partial('nav_menu'); -if (!empty($this->entries)) { - $lazyload = FreshRSS_Context::$user_conf->lazyload; - $content_width = FreshRSS_Context::$user_conf->content_width; +call_user_func($this->callbackBeforeEntries, $this); + +$lazyload = FreshRSS_Context::$user_conf->lazyload; +$content_width = FreshRSS_Context::$user_conf->content_width; ?>
-
- entries as $item) { +
entries as $item): + if ($nbEntries === 0) { + $firstEntry = $item; + } + $lastEntry = $item; + $nbEntries++; + ob_flush(); $item = Minz_ExtensionManager::callHook('entry_before_display', $item); - if (is_null($item)) { + if ($item == null) { continue; } ?>
@@ -61,15 +71,18 @@ if (!empty($this->entries)) { content() ?>
- - + renderHelper('pagination'); ?> - - - + if ($nbEntries > 0): + call_user_func($this->callbackBeforePagination, $this, $nbEntries, $firstEntry, $lastEntry); + $this->renderHelper('pagination'); +?>



- + -- cgit v1.2.3