Private
Public Access
1
0

eds contact resolver: cache when no contact found

This commit is contained in:
2026-02-21 21:40:12 -08:00
parent 9765994f14
commit a52c2e0909

View File

@@ -47,8 +47,8 @@ pub type AnyContactID = String;
#[derive(Clone)]
pub struct ContactResolver<T: ContactResolverBackend> {
backend: T,
display_name_cache: HashMap<AnyContactID, String>,
contact_id_cache: HashMap<String, AnyContactID>,
display_name_cache: HashMap<AnyContactID, Option<String>>,
contact_id_cache: HashMap<String, Option<AnyContactID>>,
}
impl<T: ContactResolverBackend> ContactResolver<T>
@@ -67,29 +67,25 @@ where
pub fn resolve_contact_id(&mut self, address: &str) -> Option<AnyContactID> {
if let Some(id) = self.contact_id_cache.get(address) {
return Some(id.clone());
return id.clone();
}
let id = self.backend.resolve_contact_id(address).map(|id| id.into());
if let Some(ref id) = id {
self.contact_id_cache
.insert(address.to_string(), id.clone());
}
self.contact_id_cache
.insert(address.to_string(), id.clone());
id
}
pub fn get_contact_display_name(&mut self, contact_id: &AnyContactID) -> Option<String> {
if let Some(display_name) = self.display_name_cache.get(contact_id) {
return Some(display_name.clone());
return display_name.clone();
}
let backend_contact_id: T::ContactID = T::ContactID::from((*contact_id).clone());
let display_name = self.backend.get_contact_display_name(&backend_contact_id);
if let Some(ref display_name) = display_name {
self.display_name_cache
.insert(contact_id.to_string(), display_name.clone());
}
self.display_name_cache
.insert(contact_id.to_string(), display_name.clone());
display_name
}