diff options
| author | wn_ <invalid@email.com> | 2025-02-15 16:44:02 +0000 |
|---|---|---|
| committer | wn_ <invalid@email.com> | 2025-02-15 16:51:25 +0000 |
| commit | e0d9ffcbc12f0bdf42cbb036646a23ee43fbf6e0 (patch) | |
| tree | 08278df32da1eb3689a58d32dc0ad5e9f461dcb2 /classes | |
| parent | 169ff6de341b20803796298d8ffea3ee4c4c4f09 (diff) | |
Only continue filter testing when there are likely more entries to check.
Prior to this, a filter test could needlessly result in up to 100 backend requests (limit 100, max_offset 10000) when the filter's associated feeds+categories have fewer than 10000 entries.
Diffstat (limited to 'classes')
| -rw-r--r-- | classes/Pref_Filters.php | 29 | ||||
| -rw-r--r-- | classes/RSSUtils.php | 5 |
2 files changed, 19 insertions, 15 deletions
diff --git a/classes/Pref_Filters.php b/classes/Pref_Filters.php index b3e378ccc..0c0a0ea03 100644 --- a/classes/Pref_Filters.php +++ b/classes/Pref_Filters.php @@ -129,28 +129,31 @@ class Pref_Filters extends Handler_Protected { if (count($scope_qparts) > 0) $query->where_raw(join($filter['match_any_rule'] ? ' OR ' : ' AND ', $scope_qparts)); - $rv = []; + $entries = $query->find_array(); - foreach ($query->find_array() as $line) { - $rc = RSSUtils::get_article_filters(array($filter), $line['title'], $line['content'], $line['link'], - $line['author'], explode(",", $line['tag_cache'])); + $rv = [ + 'pre_filtering_count' => count($entries), + 'items' => [], + ]; + + foreach ($entries as $entry) { + $rc = RSSUtils::get_article_filters(array($filter), $entry['title'], $entry['content'], $entry['link'], + $entry['author'], explode(",", $entry['tag_cache'])); if (count($rc) > 0) { - $line["content_preview"] = truncate_string(strip_tags($line["content"]), 200, '…'); + $entry["content_preview"] = truncate_string(strip_tags($entry["content"]), 200, '…'); $excerpt_length = 100; PluginHost::getInstance()->chain_hooks_callback(PluginHost::HOOK_QUERY_HEADLINES, - function ($result) use (&$line) { - $line = $result; + function ($result) use (&$entry) { + $entry = $result; }, - $line, $excerpt_length); - - $content_preview = $line["content_preview"]; + $entry, $excerpt_length); - $rv[] = "<li><span class='title'>" . $line["title"] . "</span><br/>" . - "<span class='feed'>" . $line['feed_title'] . "</span>, <span class='date'>" . mb_substr($line["date_entered"], 0, 16) . "</span>" . - "<div class='preview text-muted'>" . $content_preview . "</div>" . + $rv['items'][] = "<li><span class='title'>" . $entry["title"] . "</span><br/>" . + "<span class='feed'>" . $entry['feed_title'] . "</span>, <span class='date'>" . mb_substr($entry["date_entered"], 0, 16) . "</span>" . + "<div class='preview text-muted'>" . $entry["content_preview"] . "</div>" . "</li>"; } } diff --git a/classes/RSSUtils.php b/classes/RSSUtils.php index 3ede6bf3e..b68f7e296 100644 --- a/classes/RSSUtils.php +++ b/classes/RSSUtils.php @@ -1514,10 +1514,11 @@ class RSSUtils { } */ /** + * @todo rename this method to indicate it returns the filter actions that should be ran * @param array<int, array<string, mixed>> $filters * @param array<int, string> $tags - * @param array<int, array<string, mixed>>|null $matched_rules - * @param array<int, array<string, mixed>>|null $matched_filters + * @param array<int, array<string, mixed>>|null &$matched_rules + * @param array<int, array<string, mixed>>|null &$matched_filters * * @return array<int, array<string, string>> An array of filter action arrays with keys "type" and "param" */ |