//! What a Post read computes over the whole mailbox (every sender's tallies, the facts of senders, the senders list),//! kept while the copy is unchanged: keyed by the store's own change stamp (`Driver::change_stamp`, which moves with//! any write on this connection and any commit elsewhere), so a screen opened again over the same mail answers at//! once and a new mail is counted the moment it lands. Only data is kept here, never words that age ("just now").//!//! At his size (110,000 mails) these took 0.2 to 0.6 s each on every open (25 Nov 2026).use std::any::Any;use std::collections::HashMap;use std::sync::{Arc, Mutex, OnceLock};usesuper::super::*;typeStamp = (String, usize, u64, i64, i64);fn kept_map() -> &'staticMutex<HashMap<String, (Stamp, Arc<dynAny + Send + Sync>)>> {static KEPT: OnceLock<Mutex<HashMap<String, (Stamp, Arc<dynAny + Send + Sync>)>>> = OnceLock::new(); KEPT.get_or_init(|| Mutex::new(HashMap::new()))}fn stamp(ctx: &mutCtx<'_>) -> Option<Stamp> {let (conn, changes, version, schema) = ctx.db().change_stamp().ok()?;Some((ctx.workspace_id.to_string(), conn, changes, version, schema))}/// `make`'s answer for `key`, kept while the copy is unchanged.pub(super) fn kept<T: Clone + Send + Sync + 'static>(ctx: &mutCtx<'_>, key: &str, make: implFnOnce(&mutCtx<'_>) -> Result<T, String>) -> Result<T, String> {letSome(now) = stamp(ctx) else { return make(ctx) };// Reads lease a connection from a pool, and a stamp is one connection's: each keeps its own.let key = format!("{key}@{}", now.1);ifletSome((at, value)) = kept_map().lock().ok().and_then(|m| m.get(&key).cloned()) {if at == now {ifletSome(value) = value.downcast_ref::<T>() {returnOk(value.clone()); } } }let value = make(ctx)?;// What `make` read is what the stamp before it described: a write meanwhile moves the stamp, and the next read// makes it again.ifletOk(mut map) = kept_map().lock() {if map.len() > 256 { map.clear(); } map.insert(key, (now, Arc::new(value.clone()))); }Ok(value)}