Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/cache_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ pub struct CacheConfig {
pub recent_messages: CacheEntryConfig,
/// Message retry counts (time_to_live). Default: 5m TTL, 1000 entries.
pub message_retry_counts: CacheEntryConfig,
/// Dedup key for `UndecryptableMessage` dispatch so a server resend of
/// the same id does not surface a second notification. Default: 5m TTL,
/// 1000 entries.
pub undecryptable_dispatched: CacheEntryConfig,
/// PDO pending requests (time_to_live). Default: 30s TTL, 500 entries.
pub pdo_pending_requests: CacheEntryConfig,
/// Sender key device tracking cache (time_to_idle). Default: 1h TTI, 500 entries.
Expand Down Expand Up @@ -208,6 +212,7 @@ impl std::fmt::Debug for CacheConfig {
.field("lid_pn_cache", &self.lid_pn_cache)
.field("recent_messages", &self.recent_messages)
.field("message_retry_counts", &self.message_retry_counts)
.field("undecryptable_dispatched", &self.undecryptable_dispatched)
.field("pdo_pending_requests", &self.pdo_pending_requests)
.field("sender_key_devices_cache", &self.sender_key_devices_cache)
.field("session_locks_capacity", &self.session_locks_capacity)
Expand Down Expand Up @@ -240,6 +245,7 @@ impl Default for CacheConfig {
lid_pn_cache: CacheEntryConfig::new(one_hour, 10_000),
recent_messages: CacheEntryConfig::new(five_min, 0),
message_retry_counts: CacheEntryConfig::new(five_min, 1_000),
undecryptable_dispatched: CacheEntryConfig::new(five_min, 1_000),
pdo_pending_requests: CacheEntryConfig::new(Some(Duration::from_secs(30)), 500),
sender_key_devices_cache: CacheEntryConfig::new(one_hour, 500),
// Coordination caches hold live mutexes/senders; capacity eviction
Expand Down
15 changes: 15 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ pub struct MemoryDiagnostics {
pub recent_messages: u64,
pub sender_key_device_cache: u64,
pub message_retry_counts: u64,
pub undecryptable_dispatched: u64,
pub pdo_pending_requests: u64,
// -- Moka caches (capacity-only, no TTL) --
pub session_locks: u64,
Expand Down Expand Up @@ -213,6 +214,11 @@ impl std::fmt::Display for MemoryDiagnostics {
self.sender_key_device_cache
)?;
writeln!(f, " message_retry_counts: {}", self.message_retry_counts)?;
writeln!(
f,
" undec_dispatched: {}",
self.undecryptable_dispatched
)?;
writeln!(f, " pdo_pending_requests: {}", self.pdo_pending_requests)?;
writeln!(f, "--- Moka caches (capacity-only) ---")?;
writeln!(f, " session_locks: {}", self.session_locks)?;
Expand Down Expand Up @@ -402,6 +408,12 @@ pub struct Client {
/// Matches WhatsApp Web's MAX_RETRY = 5 behavior.
pub(crate) message_retry_counts: Cache<String, u8>,

/// Dispatch-once gate for `UndecryptableMessage`: a server resend of a
/// failed id re-enters the failure path and would otherwise fire a
/// duplicate event. Mirrors WA Web's DB-level placeholder uniqueness
/// in `WAWebMessageProcessPlaceholder`.
pub(crate) undecryptable_dispatched: Cache<ChatMessageId, ()>,
Comment thread
coderabbitai[bot] marked this conversation as resolved.

pub enable_auto_reconnect: Arc<AtomicBool>,
pub auto_reconnect_errors: Arc<AtomicU32>,

Expand Down Expand Up @@ -740,6 +752,8 @@ impl Client {

message_retry_counts: cache_config.message_retry_counts.build_with_ttl(),

undecryptable_dispatched: cache_config.undecryptable_dispatched.build_with_ttl(),

offline_sync_metrics: Arc::new(OfflineSyncMetrics {
active: AtomicBool::new(false),
total_messages: AtomicUsize::new(0),
Expand Down Expand Up @@ -1416,6 +1430,7 @@ impl Client {
recent_messages: self.recent_messages.entry_count(),
sender_key_device_cache: self.sender_key_device_cache.entry_count(),
message_retry_counts: self.message_retry_counts.entry_count(),
undecryptable_dispatched: self.undecryptable_dispatched.entry_count(),
pdo_pending_requests: self.pdo_pending_requests.entry_count(),
session_locks: self.session_locks.entry_count(),
chat_lanes: self.chat_lanes.entry_count(),
Expand Down
Loading
Loading