diff --git a/src/client/device_registry.rs b/src/client/device_registry.rs index ae9fec69b..47d3129b1 100644 --- a/src/client/device_registry.rs +++ b/src/client/device_registry.rs @@ -15,13 +15,19 @@ use super::Client; enum UserLookupKeys { /// User is a LID with known phone number mapping. /// Keys: [LID, PN] - LidWithPn { lid: String, pn: String }, + LidWithPn { + lid: wacore_binary::CompactString, + pn: wacore_binary::CompactString, + }, /// User is a phone number with known LID mapping. /// Keys: [LID, PN] - PnWithLid { lid: String, pn: String }, + PnWithLid { + lid: wacore_binary::CompactString, + pn: wacore_binary::CompactString, + }, /// Unknown user - no LID-PN mapping exists. /// Could be either a LID or PN, we don't know. - Unknown { user: String }, + Unknown { user: wacore_binary::CompactString }, } impl UserLookupKeys { @@ -61,26 +67,26 @@ impl Client { /// - `PnWithLid`: User is a phone number with known LID mapping /// - `Unknown`: No LID-PN mapping exists (could be either type) async fn resolve_lookup_keys(&self, user: &str) -> UserLookupKeys { - // Check if user is a LID (has a phone number mapping) + // Check if user is a LID (has a phone number mapping). The `user`-derived + // key is built inline via CompactString (LID/PN are short), avoiding a + // heap String per member on every group send. if let Some(pn) = self.lid_pn_cache.get_phone_number(user).await { return UserLookupKeys::LidWithPn { - lid: user.to_string(), - pn, + lid: user.into(), + pn: pn.into(), }; } // Check if user is a PN (has a LID mapping) if let Some(lid) = self.lid_pn_cache.get_current_lid(user).await { return UserLookupKeys::PnWithLid { - lid, - pn: user.to_string(), + lid: lid.into(), + pn: user.into(), }; } // Unknown user - no mapping exists - UserLookupKeys::Unknown { - user: user.to_string(), - } + UserLookupKeys::Unknown { user: user.into() } } /// Get all possible lookup keys for a user (for bidirectional lookup).