refactor(profile): look up the refresh target once

This commit is contained in:
Tunglies
2026-12-03 19:38:18 +08:00
parent c53e005f25
commit c742a9a17c
3 changed files with 30 additions and 46 deletions
+13 -14
View File
@@ -157,21 +157,20 @@ impl IProfiles {
}
pub fn get_item(&self, uid: impl AsRef<str>) -> Result<&PrfItem, ProfileNotFound> {
let uid_str = uid.as_ref();
let uid = uid.as_ref();
self.items
.iter()
.flatten()
.find(|item| item.uid.as_deref() == Some(uid))
.ok_or_else(|| ProfileNotFound { uid: uid.to_owned() })
}
if let Some(items) = self.items.as_ref() {
for each in items.iter() {
if let Some(uid_val) = &each.uid
&& uid_val.as_str() == uid_str
{
return Ok(each);
}
}
}
Err(ProfileNotFound {
uid: uid_str.to_owned(),
})
pub fn get_item_mut(&mut self, uid: &str) -> Result<&mut PrfItem, ProfileNotFound> {
self.items
.iter_mut()
.flatten()
.find(|item| item.uid.as_deref() == Some(uid))
.ok_or_else(|| ProfileNotFound { uid: uid.to_owned() })
}
/// Inserts a prepared entry after any required body write.