Files
Aether/crates/aether-runtime/state/src/score_window.rs
T
elky ecc16673eb fix: harden concurrency limits and high-RPM runtime paths
Bound request, stream, queue, and shutdown resource lifetimes. Reduce scheduler and Redis hot-path work and isolate database maintenance. Include regression coverage, load probes, and concurrency audit results.
2026-09-10 08:14:58 +08:00

26 lines
908 B
Rust

/// Maximum number of members examined by one server-side window aggregation.
pub const SCORE_WINDOW_AGGREGATION_MEMBER_LIMIT: usize = 512;
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct ScoreWindowU64Stats {
pub sum: u64,
pub positive_count: u64,
}
impl ScoreWindowU64Stats {
/// Members encode the value after their final colon. Invalid or zero values
/// do not contribute to the positive sample count.
pub fn from_members<'a>(members: impl IntoIterator<Item = &'a str>) -> Self {
let mut stats = Self::default();
for member in members {
let value = member
.rsplit_once(':')
.and_then(|(_, suffix)| suffix.parse::<u64>().ok())
.unwrap_or(0);
stats.sum = stats.sum.saturating_add(value);
stats.positive_count += u64::from(value > 0);
}
stats
}
}