server: return ids processed from send_refresh_websocket_handler

This commit is contained in:
Bill Thiede 2025-04-23 11:38:30 -07:00
parent 885bbe0a8c
commit f92c05cd28
2 changed files with 11 additions and 6 deletions

View File

@ -200,15 +200,21 @@ async fn send_refresh_websocket_handler(
None => Some(10), None => Some(10),
}; };
if let Err(err) = label_unprocessed(&nm, &pool, false, limit, "tag:unprocessed").await { let mut ids = None;
error!("Failed to label_unprocessed: {err:?}"); match label_unprocessed(&nm, &pool, false, limit, "tag:unprocessed").await {
Ok(i) => ids = Some(i),
Err(err) => error!("Failed to label_unprocessed: {err:?}"),
}; };
connection_tracker connection_tracker
.lock() .lock()
.await .await
.send_message_all(WebsocketMessage::RefreshMessages) .send_message_all(WebsocketMessage::RefreshMessages)
.await; .await;
"refresh triggered" if let Some(ids) = ids {
format!("{ids:?}")
} else {
"refresh triggered".to_string()
}
} }
async fn watch_new( async fn watch_new(

View File

@ -946,7 +946,7 @@ pub async fn label_unprocessed(
dryrun: bool, dryrun: bool,
limit: Option<usize>, limit: Option<usize>,
query: &str, query: &str,
) -> Result<(), ServerError> { ) -> Result<Box<[String]>, ServerError> {
use futures::StreamExt; use futures::StreamExt;
let ids = nm.message_ids(query)?; let ids = nm.message_ids(query)?;
info!( info!(
@ -990,7 +990,6 @@ pub async fn label_unprocessed(
// Only process the first file path is multiple files have the same id // Only process the first file path is multiple files have the same id
let path = files.iter().next().unwrap(); let path = files.iter().next().unwrap();
let file = File::open(&path)?; let file = File::open(&path)?;
info!("mmaping {path}");
let mmap = unsafe { MmapOptions::new().map(&file)? }; let mmap = unsafe { MmapOptions::new().map(&file)? };
let m = parse_mail(&mmap)?; let m = parse_mail(&mmap)?;
let (matched_rule, add_tags) = find_tags(&rules, &m.headers); let (matched_rule, add_tags) = find_tags(&rules, &m.headers);
@ -1067,7 +1066,7 @@ pub async fn label_unprocessed(
} }
} }
Ok(()) Ok(ids.into())
} }
fn find_tags<'a, 'b>(rules: &'a [Rule], headers: &'b [MailHeader]) -> (bool, HashSet<&'a str>) { fn find_tags<'a, 'b>(rules: &'a [Rule], headers: &'b [MailHeader]) -> (bool, HashSet<&'a str>) {
let mut matched_rule = false; let mut matched_rule = false;