diff options
| author | 2020-02-29 18:19:09 +0100 | |
|---|---|---|
| committer | 2020-02-29 18:19:09 +0100 | |
| commit | 0f94402b7e8b7e25ee605f830b7c7becbe78ba8b (patch) | |
| tree | 473adf4e21e8cbe2f6e36eae69dca3ed8b39a424 /app/views/index/reader.phtml | |
| parent | e9f879b411ac6af9d102702fb52c8deff161b0e6 (diff) | |
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
Diffstat (limited to 'app/views/index/reader.phtml')
| -rw-r--r-- | app/views/index/reader.phtml | 39 |
1 files changed, 26 insertions, 13 deletions
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; ?> <div id="stream" class="reader"> <div id="new-article"> <a href="<?= Minz_Url::display(Minz_Request::currentRequest()) ?>"><?= _t('gen.js.new_article'); /* TODO: move string in JS*/ ?></a> - </div> - <?php foreach ($this->entries as $item) { + </div><?php + $firstEntry = null; + $lastEntry = null; + $nbEntries = 0; + foreach ($this->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; } ?><div class="flux<?= !$item->isRead() ? ' not_read' : '' ?><?= $item->isFavorite() ? ' favorite' : '' ?>" id="flux_<?= $item->id() ?>"> @@ -61,15 +71,18 @@ if (!empty($this->entries)) { <?= $item->content() ?> </div> </div> - </div> - <?php } ?> + </div><?php + endforeach; - <?php $this->renderHelper('pagination'); ?> -</div> - -<?php } else { ?> + if ($nbEntries > 0): + call_user_func($this->callbackBeforePagination, $this, $nbEntries, $firstEntry, $lastEntry); + $this->renderHelper('pagination'); +?></div><?php + else: + ob_end_clean(); //Discard the articles headers, as we have no articles +?> <div id="stream" class="prompt alert alert-warn reader"> <h2><?= _t('index.feed.empty') ?></h2> <a href="<?= _url('subscription', 'index') ?>"><?= _t('index.feed.add') ?></a><br /><br /> </div> -<?php } ?> +<?php endif; ?> |
