From 62e09eedd561b44987ec8a4c032d4608088d30c1 Mon Sep 17 00:00:00 2001 From: Raicuparta Date: Sat, 9 Nov 2024 19:02:43 +0100 Subject: [PATCH 1/4] send games to frontend in batches --- backend/tauri-app/src/main.rs | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/backend/tauri-app/src/main.rs b/backend/tauri-app/src/main.rs index c7b619a4..cf99b6e2 100644 --- a/backend/tauri-app/src/main.rs +++ b/backend/tauri-app/src/main.rs @@ -238,7 +238,7 @@ fn refresh_game_mods_and_exe(installed_game: &InstalledGame, handle: &AppHandle) { let mut installed_games = installed_games_state.get_data()?; installed_games.insert(refreshed_game.id.clone(), refreshed_game.clone()); - update_installed_games_state(handle, &installed_game.provider, installed_games); + update_installed_games_state(handle, &installed_game.provider, &installed_games); } Ok(()) @@ -394,7 +394,7 @@ async fn fetch_remote_games() -> Result> { fn update_installed_games_state( handle: &AppHandle, provider_id: &ProviderId, - installed_games: HashMap, + installed_games: &HashMap, ) { if let Some(mutex) = handle.app_state().installed_games.get(provider_id) { update_state(installed_games.clone(), mutex); @@ -405,7 +405,7 @@ fn update_installed_games_state( fn update_owned_games_state( handle: &AppHandle, provider_id: &ProviderId, - owned_games: HashMap, + owned_games: &HashMap, ) { if let Some(mutex) = handle.app_state().owned_games.get(provider_id) { update_state(owned_games.clone(), mutex); @@ -429,23 +429,36 @@ async fn get_provider_games(handle: AppHandle, provider_id: ProviderId) -> Resul } else { installed_games = cache.data.installed_games.clone(); owned_games = cache.data.owned_games.clone(); - update_installed_games_state(&handle, &provider_id, installed_games.clone()); - update_owned_games_state(&handle, &provider_id, owned_games.clone()); + update_installed_games_state(&handle, &provider_id, &installed_games); + update_owned_games_state(&handle, &provider_id, &owned_games); } let provider = provider::get_provider(provider_id)?; + let mut owned_count = 0; + let mut installed_count = 0; + // Sending to frontend too often makes things slow, + // especially for very large libraries where I'm cloning the entire game map every time I push it. + // So we send the game lists in batches! + const BATCH_SIZE: usize = 500; provider .get_games( |game: InstalledGame| { + installed_count += 1; installed_games_without_cache.insert(game.id.clone(), game.clone()); installed_games.insert(game.id.clone(), game); - update_installed_games_state(&handle, &provider_id, installed_games.clone()); + if (installed_count % BATCH_SIZE) == 0 { + update_installed_games_state(&handle, &provider_id, &installed_games); + } }, |game: OwnedGame| { + owned_count += 1; owned_games_without_cache.insert(game.global_id.clone(), game.clone()); owned_games.insert(game.global_id.clone(), game); - update_owned_games_state(&handle, &provider_id, owned_games.clone()); + if (owned_count % BATCH_SIZE) == 0 { + log::info!("Found {owned_count} owned games for provider {provider_id}"); + update_owned_games_state(&handle, &provider_id, &owned_games); + } }, ) .await @@ -455,8 +468,8 @@ async fn get_provider_games(handle: AppHandle, provider_id: ProviderId) -> Resul log::warn!("Failed to get games for provider {provider_id}. User might just not have it. Error: {err}"); }); - update_installed_games_state(&handle, &provider_id, installed_games_without_cache.clone()); - update_owned_games_state(&handle, &provider_id, owned_games_without_cache.clone()); + update_installed_games_state(&handle, &provider_id, &installed_games_without_cache); + update_owned_games_state(&handle, &provider_id, &owned_games_without_cache); cache .set_data(ProviderData { @@ -486,7 +499,7 @@ async fn add_game(path: PathBuf, handle: AppHandle) -> Result { { let mut installed_games = installed_games_state.get_data()?; installed_games.insert(installed_game.id.clone(), installed_game.clone()); - update_installed_games_state(&handle, &installed_game.provider, installed_games); + update_installed_games_state(&handle, &installed_game.provider, &installed_games); } handle.emit_safe(events::SelectInstalledGame(installed_game.id.clone())); @@ -508,7 +521,7 @@ async fn remove_game(installed_game: InstalledGame, handle: AppHandle) -> Result { let mut installed_games = installed_games_state.get_data()?; installed_games.remove(&installed_game.id); - update_installed_games_state(&handle, &installed_game.provider, installed_games); + update_installed_games_state(&handle, &installed_game.provider, &installed_games); } Ok(()) From 5a658ad9ec3d9bc98cef313ded7aeac7ae424927 Mon Sep 17 00:00:00 2001 From: Raicuparta Date: Sat, 9 Nov 2024 19:06:35 +0100 Subject: [PATCH 2/4] Bump version 0.14.0 --- backend/Cargo.lock | 6 +++--- backend/Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/Cargo.lock b/backend/Cargo.lock index f2248265..bde4704b 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -3351,7 +3351,7 @@ checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" [[package]] name = "rai-pal-core" -version = "0.13.1" +version = "0.14.0" dependencies = [ "base64 0.22.1", "byteorder", @@ -3381,7 +3381,7 @@ dependencies = [ [[package]] name = "rai-pal-proc-macros" -version = "0.13.1" +version = "0.14.0" dependencies = [ "quote", "serde", @@ -3390,7 +3390,7 @@ dependencies = [ [[package]] name = "rai-pal-tauri" -version = "0.13.1" +version = "0.14.0" dependencies = [ "log", "rai-pal-core", diff --git a/backend/Cargo.toml b/backend/Cargo.toml index d869e7e2..e62cc566 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -3,7 +3,7 @@ members = ["proc-macros", "core", "tauri-app"] resolver = "2" [workspace.package] -version = "0.13.1" +version = "0.14.0" authors = ["Raicuparta"] license = "GPL-3.0-or-later" repository = "https://github.com/Raicuparta/rai-pal" From 5a9d0865f101089bdc7cde9d4399218497eef03d Mon Sep 17 00:00:00 2001 From: Raicuparta Date: Sat, 9 Nov 2024 19:55:16 +0100 Subject: [PATCH 3/4] cleanup --- backend/tauri-app/src/main.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/backend/tauri-app/src/main.rs b/backend/tauri-app/src/main.rs index cf99b6e2..659a6878 100644 --- a/backend/tauri-app/src/main.rs +++ b/backend/tauri-app/src/main.rs @@ -441,8 +441,7 @@ async fn get_provider_games(handle: AppHandle, provider_id: ProviderId) -> Resul // So we send the game lists in batches! const BATCH_SIZE: usize = 500; - provider - .get_games( + provider.get_games( |game: InstalledGame| { installed_count += 1; installed_games_without_cache.insert(game.id.clone(), game.clone()); @@ -456,7 +455,6 @@ async fn get_provider_games(handle: AppHandle, provider_id: ProviderId) -> Resul owned_games_without_cache.insert(game.global_id.clone(), game.clone()); owned_games.insert(game.global_id.clone(), game); if (owned_count % BATCH_SIZE) == 0 { - log::info!("Found {owned_count} owned games for provider {provider_id}"); update_owned_games_state(&handle, &provider_id, &owned_games); } }, From 612f31a5f95f70344af39f38621309e6d4d10516 Mon Sep 17 00:00:00 2001 From: Raicuparta Date: Sat, 9 Nov 2024 20:15:35 +0100 Subject: [PATCH 4/4] fix publish changelog --- publish.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/publish.ps1 b/publish.ps1 index 90ac6e1d..6bf4ebd1 100644 --- a/publish.ps1 +++ b/publish.ps1 @@ -34,7 +34,7 @@ $version = [regex]::Match($msiName, '.+_(.+)_.+_.+').Groups[1].Value $signature = Get-Content -Path "$msiFolder/*.sig" -Raw # Read changelog from environment variable. -$changelog = $env:RAI_PAL_CHANGELOG -or "Someone forgot to include a changelog." +$changelog = $env:RAI_PAL_CHANGELOG ?? "Someone forgot to include a changelog." # Create json that's used by Rai Pal for checking updates. $updaterJson = ConvertTo-Json -InputObjec @{