fix web performance
This commit is contained in:
@@ -105,7 +105,21 @@ impl Person {
|
||||
|
||||
/// Get profile avatar
|
||||
pub fn avatar(&self) -> SharedString {
|
||||
self.metadata()
|
||||
// On web, the browser blocks cross-origin image fetches unless the
|
||||
// picture host sends CORS headers, so remote avatars can never load
|
||||
// there. Each doomed fetch still triggers a full-window repaint when
|
||||
// it fails, which is very costly on wasm's single main thread when a
|
||||
// list renders many avatars at once. Fall back to the bundled avatar
|
||||
// for remote pictures on web.
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
if let Some(picture) = self.metadata.picture.as_ref()
|
||||
&& !picture.is_empty()
|
||||
&& url::Url::parse(picture).is_ok_and(|url| matches!(url.scheme(), "http" | "https"))
|
||||
{
|
||||
return "brand/avatar.png".into();
|
||||
}
|
||||
|
||||
self.metadata
|
||||
.picture
|
||||
.as_ref()
|
||||
.filter(|picture| !picture.is_empty())
|
||||
@@ -115,13 +129,13 @@ impl Person {
|
||||
|
||||
/// Get profile name
|
||||
pub fn name(&self) -> SharedString {
|
||||
if let Some(display_name) = self.metadata().display_name.as_ref()
|
||||
if let Some(display_name) = self.metadata.display_name.as_ref()
|
||||
&& !display_name.is_empty()
|
||||
{
|
||||
return SharedString::from(display_name.trim());
|
||||
}
|
||||
|
||||
if let Some(name) = self.metadata().name.as_ref()
|
||||
if let Some(name) = self.metadata.name.as_ref()
|
||||
&& !name.is_empty()
|
||||
{
|
||||
return SharedString::from(name.trim());
|
||||
|
||||
Reference in New Issue
Block a user