mirror of
https://git.tt-rss.org/fox/tt-rss.git
synced 2025-08-06 22:27:42 +02:00
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.
This commit is contained in:
parent
169ff6de34
commit
e0d9ffcbc1
@ -129,28 +129,31 @@ class Pref_Filters extends Handler_Protected {
|
|||||||
if (count($scope_qparts) > 0)
|
if (count($scope_qparts) > 0)
|
||||||
$query->where_raw(join($filter['match_any_rule'] ? ' OR ' : ' AND ', $scope_qparts));
|
$query->where_raw(join($filter['match_any_rule'] ? ' OR ' : ' AND ', $scope_qparts));
|
||||||
|
|
||||||
$rv = [];
|
$entries = $query->find_array();
|
||||||
|
|
||||||
foreach ($query->find_array() as $line) {
|
$rv = [
|
||||||
$rc = RSSUtils::get_article_filters(array($filter), $line['title'], $line['content'], $line['link'],
|
'pre_filtering_count' => count($entries),
|
||||||
$line['author'], explode(",", $line['tag_cache']));
|
'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) {
|
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;
|
$excerpt_length = 100;
|
||||||
|
|
||||||
PluginHost::getInstance()->chain_hooks_callback(PluginHost::HOOK_QUERY_HEADLINES,
|
PluginHost::getInstance()->chain_hooks_callback(PluginHost::HOOK_QUERY_HEADLINES,
|
||||||
function ($result) use (&$line) {
|
function ($result) use (&$entry) {
|
||||||
$line = $result;
|
$entry = $result;
|
||||||
},
|
},
|
||||||
$line, $excerpt_length);
|
$entry, $excerpt_length);
|
||||||
|
|
||||||
$content_preview = $line["content_preview"];
|
$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>" .
|
||||||
$rv[] = "<li><span class='title'>" . $line["title"] . "</span><br/>" .
|
"<div class='preview text-muted'>" . $entry["content_preview"] . "</div>" .
|
||||||
"<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>" .
|
|
||||||
"</li>";
|
"</li>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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, array<string, mixed>> $filters
|
||||||
* @param array<int, string> $tags
|
* @param array<int, string> $tags
|
||||||
* @param array<int, array<string, mixed>>|null $matched_rules
|
* @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_filters
|
||||||
*
|
*
|
||||||
* @return array<int, array<string, string>> An array of filter action arrays with keys "type" and "param"
|
* @return array<int, array<string, string>> An array of filter action arrays with keys "type" and "param"
|
||||||
*/
|
*/
|
||||||
|
@ -30,52 +30,48 @@ const Filters = {
|
|||||||
params.offset = offset;
|
params.offset = offset;
|
||||||
params.limit = test_dialog.limit;
|
params.limit = test_dialog.limit;
|
||||||
|
|
||||||
console.log("getTestResults:" + offset);
|
|
||||||
|
|
||||||
xhr.json("backend.php", params, (result) => {
|
xhr.json("backend.php", params, (result) => {
|
||||||
try {
|
try {
|
||||||
if (result && test_dialog && test_dialog.open) {
|
if (result && test_dialog && test_dialog.open) {
|
||||||
test_dialog.results += result.length;
|
|
||||||
|
|
||||||
console.log("got results:" + result.length);
|
|
||||||
|
|
||||||
const loading_message = test_dialog.domNode.querySelector(".loading-message");
|
const loading_message = test_dialog.domNode.querySelector(".loading-message");
|
||||||
const results_list = test_dialog.domNode.querySelector(".filter-results-list");
|
const results_list = test_dialog.domNode.querySelector(".filter-results-list");
|
||||||
|
|
||||||
loading_message.innerHTML = __("Looking for articles (%d processed, %f found)...")
|
if (result.pre_filtering_count > 0) {
|
||||||
.replace("%f", test_dialog.results)
|
test_dialog.results += result.items.length;
|
||||||
.replace("%d", offset);
|
|
||||||
|
|
||||||
console.log(offset + " " + test_dialog.max_offset);
|
loading_message.innerHTML = __("Looking for articles (%d processed, %f found)...")
|
||||||
|
.replace("%f", test_dialog.results)
|
||||||
|
.replace("%d", offset);
|
||||||
|
|
||||||
for (let i = 0; i < result.length; i++) {
|
for (let i = 0; i < result.items.length; i++) {
|
||||||
const tmp = dojo.create("div", { innerHTML: result[i]});
|
const tmp = dojo.create("div", { innerHTML: result.items[i]});
|
||||||
|
|
||||||
results_list.innerHTML += tmp.innerHTML;
|
results_list.innerHTML += tmp.innerHTML;
|
||||||
}
|
|
||||||
|
|
||||||
if (test_dialog.results < 30 && offset < test_dialog.max_offset) {
|
|
||||||
|
|
||||||
// get the next batch
|
|
||||||
window.setTimeout(function () {
|
|
||||||
test_dialog.getTestResults(params, offset + test_dialog.limit);
|
|
||||||
}, 0);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// all done
|
|
||||||
|
|
||||||
test_dialog.domNode.querySelector(".loading-indicator").hide();
|
|
||||||
|
|
||||||
if (test_dialog.results == 0) {
|
|
||||||
results_list.innerHTML = `<li class="text-center text-muted">
|
|
||||||
${__('No recent articles matching this filter have been found.')}</li>`;
|
|
||||||
|
|
||||||
loading_message.innerHTML = __("Articles matching this filter:");
|
|
||||||
} else {
|
|
||||||
loading_message.innerHTML = __("Found at least %d articles matching this filter:")
|
|
||||||
.replace("%d", test_dialog.results);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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) {
|
||||||
|
window.setTimeout(function () {
|
||||||
|
test_dialog.getTestResults(params, offset + test_dialog.limit);
|
||||||
|
}, 0);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// all done-- either the backend found no more pre-filtering entries, or test limits were reached
|
||||||
|
test_dialog.domNode.querySelector(".loading-indicator").hide();
|
||||||
|
|
||||||
|
if (test_dialog.results == 0) {
|
||||||
|
results_list.innerHTML = `<li class="text-center text-muted">
|
||||||
|
${__('No recent articles matching this filter have been found.')}</li>`;
|
||||||
|
|
||||||
|
loading_message.innerHTML = __("Articles matching this filter:");
|
||||||
|
} else {
|
||||||
|
loading_message.innerHTML = __("Found at least %d articles matching this filter:")
|
||||||
|
.replace("%d", test_dialog.results);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (!result) {
|
} else if (!result) {
|
||||||
|
Loading…
Reference in New Issue
Block a user