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:
parent
2851c0a7ab
commit
c32fbee905
1 changed files with 6 additions and 7 deletions
|
|
@ -3,7 +3,6 @@
|
||||||
//! `chanlog = #channel` is configured.
|
//! `chanlog = #channel` is configured.
|
||||||
|
|
||||||
use crate::server::Server;
|
use crate::server::Server;
|
||||||
use crate::Uid;
|
|
||||||
|
|
||||||
/// Tee `msg` to the configured chanlog channel (if set and it exists). Called at
|
/// 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.
|
/// 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 {
|
let Some(chan) = s.conf("chanlog") else {
|
||||||
return;
|
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
|
return; // channel not created yet — nothing to log into
|
||||||
};
|
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
// 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);
|
||||||
|
s.to_channel(&key, &line, None);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue