chanlog: fan the mirrored notice via to_channel (Arc-shared line, per-recipient server-time) instead of collecting a members Vec and cloning the String per member

This commit is contained in:
Jean Chevronnet 2026-08-19 01:29:48 +00:00
parent 2851c0a7ab
commit c32fbee905

View file

@ -3,7 +3,6 @@
//! `chanlog = #channel` is configured.
use crate::server::Server;
use crate::Uid;
/// Tee `msg` to the configured chanlog channel (if set and it exists). Called at
/// the tail of `Server::snotice`. Read-only over server state, so it can't loop.
@ -11,12 +10,12 @@ pub fn tee(s: &Server, msg: &str) {
let Some(chan) = s.conf("chanlog") else {
return;
};
let Some(ch) = s.channels.get(&chan.to_ascii_lowercase()) else {
let key = chan.to_ascii_lowercase();
if !s.channels.contains_key(&key) {
return; // channel not created yet — nothing to log into
};
}
// to_channel builds the line once and shares it by Arc across members (and adds
// the server-time tag per recipient) instead of cloning a String per member.
let line = format!(":{} NOTICE {chan} :{msg}", s.name);
let members: Vec<Uid> = ch.members.keys().copied().collect();
for u in members {
s.send(u, line.clone());
}
s.to_channel(&key, &line, None);
}