From e0d9ffcbc12f0bdf42cbb036646a23ee43fbf6e0 Mon Sep 17 00:00:00 2001 From: wn_ Date: Sat, 15 Feb 2025 16:44:02 +0000 Subject: 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. --- classes/Pref_Filters.php | 29 ++++++++++++++++------------- classes/RSSUtils.php | 5 +++-- 2 files changed, 19 insertions(+), 15 deletions(-) (limited to 'classes') 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[] = "
  • " . $line["title"] . "
    " . - "" . $line['feed_title'] . ", " . mb_substr($line["date_entered"], 0, 16) . "" . - "
    " . $content_preview . "
    " . + $rv['items'][] = "
  • " . $entry["title"] . "
    " . + "" . $entry['feed_title'] . ", " . mb_substr($entry["date_entered"], 0, 16) . "" . + "
    " . $entry["content_preview"] . "
    " . "
  • "; } } 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> $filters * @param array $tags - * @param array>|null $matched_rules - * @param array>|null $matched_filters + * @param array>|null &$matched_rules + * @param array>|null &$matched_filters * * @return array> An array of filter action arrays with keys "type" and "param" */ -- cgit v1.2.3-54-g00ecf From 777c2b4c97d1d7088d15bb56f8835fcf57d2f2f3 Mon Sep 17 00:00:00 2001 From: wn_ Date: Sat, 15 Feb 2025 20:39:25 +0000 Subject: Move filter test results HTML building to the frontend. --- classes/Pref_Filters.php | 10 ++++++---- js/CommonFilters.js | 11 ++++------- 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'classes') diff --git a/classes/Pref_Filters.php b/classes/Pref_Filters.php index 0c0a0ea03..cfad881a4 100644 --- a/classes/Pref_Filters.php +++ b/classes/Pref_Filters.php @@ -151,10 +151,12 @@ class Pref_Filters extends Handler_Protected { }, $entry, $excerpt_length); - $rv['items'][] = "
  • " . $entry["title"] . "
    " . - "" . $entry['feed_title'] . ", " . mb_substr($entry["date_entered"], 0, 16) . "" . - "
    " . $entry["content_preview"] . "
    " . - "
  • "; + $rv['items'][] = [ + 'title' => $entry['title'], + 'feed_title' => $entry['feed_title'], + 'date' => mb_substr($entry['date_entered'], 0, 16), + 'content_preview' => $entry['content_preview'], + ]; } } diff --git a/js/CommonFilters.js b/js/CommonFilters.js index 7b7d64958..b7bb69a15 100644 --- a/js/CommonFilters.js +++ b/js/CommonFilters.js @@ -43,16 +43,13 @@ const Filters = { .replace("%f", test_dialog.results) .replace("%d", offset); - for (let i = 0; i < result.items.length; i++) { - const tmp = dojo.create("div", { innerHTML: result.items[i]}); - - results_list.innerHTML += tmp.innerHTML; - } + results_list.innerHTML += result.items.reduce((current, item) => current + `
  • ${item.title}
    + ${item.feed_title}, ${item.date} +
    ${item.content_preview}
  • `, ''); // get the next batch if there may be more available and testing limits haven't been reached if (result.pre_filtering_count === test_dialog.limit && - test_dialog.results < 30 && - offset < test_dialog.max_offset) { + test_dialog.results < 30 && offset < test_dialog.max_offset) { window.setTimeout(function () { test_dialog.getTestResults(params, offset + test_dialog.limit); }, 0); -- cgit v1.2.3-54-g00ecf