feat: improve recent worlds loading performance (#5079)

* Improve recent worlds loading performance

* Make recent worlds not cause a layout shift by loading them asynchronously

* Fix formatting

* fix formatting

---------

Co-authored-by: Creeperkatze <178587183+Creeperkatze@users.noreply.github.com>
Co-authored-by: Prospector <6166773+Prospector@users.noreply.github.com>
Co-authored-by: Calum H. <contact@cal.engineer>
Co-authored-by: Calum H. <calum@modrinth.com>
This commit is contained in:
Arthur
2026-04-18 19:01:54 +02:00
committed by GitHub
parent dd51c08a18
commit b9e7b54b4e
3 changed files with 28 additions and 28 deletions

View File

@@ -31,7 +31,6 @@ use std::path::{Path, PathBuf};
use std::sync::LazyLock;
use std::time::Instant;
use tokio::io::AsyncWriteExt;
use tokio::task::JoinSet;
use tokio_util::compat::FuturesAsyncWriteCompatExt;
use url::Url;
@@ -404,7 +403,6 @@ async fn get_server_worlds_in_profile(
.await
.ok();
let first_server_index = worlds.len();
for (index, server) in servers.into_iter().enumerate() {
if server.hidden {
// TODO: Figure out whether we want to hide or show direct connect servers
@@ -436,31 +434,6 @@ async fn get_server_worlds_in_profile(
};
worlds.push(world);
}
if let Some(join_log) = join_log {
let mut futures = JoinSet::new();
for (index, world) in worlds.iter().enumerate().skip(first_server_index)
{
// We can't check for the profile already having a last_played, in case the user joined
// the target address directly more recently. This is often the case when using
// quick-play before 1.20.
if let WorldDetails::Server { address, .. } = &world.details
&& let Ok((host, port)) = parse_server_address(address)
{
let host = host.to_owned();
futures.spawn(async move {
resolve_server_address(&host, port)
.await
.ok()
.map(|x| (index, x))
});
}
}
for (index, address) in futures.join_all().await.into_iter().flatten() {
worlds[index].last_played = join_log.get(&address).copied();
}
}
Ok(())
}