aboutsummaryrefslogtreecommitdiff
path: root/app/Models
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2022-03-06 23:36:35 +0100
committerGravatar GitHub <noreply@github.com> 2022-03-06 23:36:35 +0100
commitcc6deadf69cfee717c29bb23c3405d1d730455a7 (patch)
tree5604c54102a12f3692a76c49588e1e4306e6a261 /app/Models
parenta9e23bd1203f36006f7b00654132f48a913b2279 (diff)
Faster $simplePie->get_items() (#4263)
Implement one of the TODOs from https://github.com/FreshRSS/FreshRSS/pull/4220 : use `$simplePie->get_items()` instead of very slow `$simplePie->get_item($i)`
Diffstat (limited to 'app/Models')
-rw-r--r--app/Models/Feed.php18
1 files changed, 12 insertions, 6 deletions
diff --git a/app/Models/Feed.php b/app/Models/Feed.php
index 934036845..baaf448f8 100644
--- a/app/Models/Feed.php
+++ b/app/Models/Feed.php
@@ -395,9 +395,12 @@ class FreshRSS_Feed extends Minz_Model {
$guids = [];
$hasBadGuids = $this->attributes('hasBadGuids');
- // TODO: Replace very slow $simplePie->get_item($i) by getting all items at once
- for ($i = $simplePie->get_item_quantity() - 1; $i >= 0; $i--) {
- $item = $simplePie->get_item($i);
+ $items = $simplePie->get_items();
+ if (empty($items)) {
+ return $guids;
+ }
+ for ($i = count($items) - 1; $i >= 0; $i--) {
+ $item = $items[$i];
if ($item == null) {
continue;
}
@@ -423,10 +426,13 @@ class FreshRSS_Feed extends Minz_Model {
public function loadEntries(SimplePie $simplePie) {
$hasBadGuids = $this->attributes('hasBadGuids');
+ $items = $simplePie->get_items();
+ if (empty($items)) {
+ return;
+ }
// We want chronological order and SimplePie uses reverse order.
- // TODO: Replace very slow $simplePie->get_item($i) by getting all items at once
- for ($i = $simplePie->get_item_quantity() - 1; $i >= 0; $i--) {
- $item = $simplePie->get_item($i);
+ for ($i = count($items) - 1; $i >= 0; $i--) {
+ $item = $items[$i];
if ($item == null) {
continue;
}