Check cancel in multithreaded fuzzy matching (#22525)
For both the strings and paths multithreaded matching it would still aggregate the response even though it is unneeded. It now checks cancel. In the paths matcher, cancel is now checked within the loop, since it was calling `match_candidates` even though no further results would be computed. Release Notes: - N/A
This commit is contained in:
parent
6ef5d8f748
commit
51ac2d3667
2 changed files with 17 additions and 2 deletions
|
@ -3,7 +3,10 @@ use std::{
|
|||
borrow::Cow,
|
||||
cmp::{self, Ordering},
|
||||
path::Path,
|
||||
sync::{atomic::AtomicBool, Arc},
|
||||
sync::{
|
||||
atomic::{self, AtomicBool},
|
||||
Arc,
|
||||
},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
|
@ -154,6 +157,10 @@ pub async fn match_path_sets<'a, Set: PathMatchCandidateSet<'a>>(
|
|||
|
||||
let mut tree_start = 0;
|
||||
for candidate_set in candidate_sets {
|
||||
if cancel_flag.load(atomic::Ordering::Relaxed) {
|
||||
break;
|
||||
}
|
||||
|
||||
let tree_end = tree_start + candidate_set.len();
|
||||
|
||||
if tree_start < segment_end && segment_start < tree_end {
|
||||
|
@ -202,6 +209,10 @@ pub async fn match_path_sets<'a, Set: PathMatchCandidateSet<'a>>(
|
|||
})
|
||||
.await;
|
||||
|
||||
if cancel_flag.load(atomic::Ordering::Relaxed) {
|
||||
return Vec::new();
|
||||
}
|
||||
|
||||
let mut results = segment_results.concat();
|
||||
util::truncate_to_bottom_n_sorted_by(&mut results, max_results, &|a, b| b.cmp(a));
|
||||
results
|
||||
|
|
|
@ -8,7 +8,7 @@ use std::{
|
|||
cmp::{self, Ordering},
|
||||
iter,
|
||||
ops::Range,
|
||||
sync::atomic::AtomicBool,
|
||||
sync::atomic::{self, AtomicBool},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
@ -178,6 +178,10 @@ pub async fn match_strings(
|
|||
})
|
||||
.await;
|
||||
|
||||
if cancel_flag.load(atomic::Ordering::Relaxed) {
|
||||
return Vec::new();
|
||||
}
|
||||
|
||||
let mut results = segment_results.concat();
|
||||
util::truncate_to_bottom_n_sorted_by(&mut results, max_results, &|a, b| b.cmp(a));
|
||||
results
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue