dont do heavy size calc
This commit is contained in:
@@ -21,7 +21,7 @@ struct LanSpreadState {
|
|||||||
games: Arc<RwLock<GameDB>>,
|
games: Arc<RwLock<GameDB>>,
|
||||||
games_in_download: Arc<RwLock<HashSet<String>>>,
|
games_in_download: Arc<RwLock<HashSet<String>>>,
|
||||||
games_folder: Arc<RwLock<String>>,
|
games_folder: Arc<RwLock<String>>,
|
||||||
// Add access to peer game database for size calculations
|
#[allow(dead_code)]
|
||||||
peer_game_db: Arc<RwLock<PeerGameDB>>,
|
peer_game_db: Arc<RwLock<PeerGameDB>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -444,23 +444,7 @@ fn update_game_installation_state(game: &mut Game, games_root: &Path) {
|
|||||||
let installed = downloaded && local_install_is_ready(&game_path);
|
let installed = downloaded && local_install_is_ready(&game_path);
|
||||||
game.installed = installed;
|
game.installed = installed;
|
||||||
|
|
||||||
// Calculate size from local files if available (highest priority)
|
// Size stays anchored to bundled game.db; skip expensive recalculation.
|
||||||
if downloaded || installed {
|
|
||||||
match calculate_directory_size_sync(&game_path) {
|
|
||||||
Ok(local_size) => {
|
|
||||||
game.size = local_size;
|
|
||||||
log::debug!(
|
|
||||||
"Updated size for game {} from local files: {} bytes",
|
|
||||||
game.id,
|
|
||||||
local_size
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
log::warn!("Failed to calculate local size for game {}: {e}", game.id);
|
|
||||||
// Keep the existing size (will fallback to peer/game.db later)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if installed {
|
if installed {
|
||||||
log::debug!("Set {game} to installed");
|
log::debug!("Set {game} to installed");
|
||||||
@@ -487,7 +471,8 @@ fn update_game_installation_state(game: &mut Game, games_root: &Path) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Synchronous version of `calculate_directory_size` for use in non-async contexts
|
/// Left in place for potential re-enablement. Currently not invoked to avoid expensive IO.
|
||||||
|
#[allow(dead_code)]
|
||||||
fn calculate_directory_size_sync(dir: &Path) -> eyre::Result<u64> {
|
fn calculate_directory_size_sync(dir: &Path) -> eyre::Result<u64> {
|
||||||
let mut total_size = 0u64;
|
let mut total_size = 0u64;
|
||||||
|
|
||||||
@@ -504,19 +489,20 @@ fn calculate_directory_size_sync(dir: &Path) -> eyre::Result<u64> {
|
|||||||
Ok(total_size)
|
Ok(total_size)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calculate total size from a list of file descriptions (used for peer majority calculation)
|
/// Used for peer-majority calculations but currently disabled.
|
||||||
|
#[allow(dead_code)]
|
||||||
fn calculate_size_from_file_descriptions(
|
fn calculate_size_from_file_descriptions(
|
||||||
file_descriptions: &[lanspread_db::db::GameFileDescription],
|
file_descriptions: &[lanspread_db::db::GameFileDescription],
|
||||||
) -> u64 {
|
) -> u64 {
|
||||||
file_descriptions
|
file_descriptions
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|desc| !desc.is_dir) // Only count files, not directories
|
.filter(|desc| !desc.is_dir)
|
||||||
.map(|desc| desc.size)
|
.map(|desc| desc.size)
|
||||||
.sum()
|
.sum()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update game sizes from peer majority files when local files are not available
|
/// Future hook for reintroducing peer-driven size updates.
|
||||||
/// This implements the second priority: "we don't have the game but 1-n peers have. Use the majority files for that game, calculate a total size"
|
#[allow(dead_code)]
|
||||||
async fn update_game_sizes_from_peers(
|
async fn update_game_sizes_from_peers(
|
||||||
games: &mut std::collections::HashMap<String, Game>,
|
games: &mut std::collections::HashMap<String, Game>,
|
||||||
peer_game_db: &Arc<RwLock<PeerGameDB>>,
|
peer_game_db: &Arc<RwLock<PeerGameDB>>,
|
||||||
@@ -526,9 +512,7 @@ async fn update_game_sizes_from_peers(
|
|||||||
let peer_db = peer_game_db.read().await;
|
let peer_db = peer_game_db.read().await;
|
||||||
|
|
||||||
for game in games.values_mut() {
|
for game in games.values_mut() {
|
||||||
// Only update sizes for games that don't have local files
|
|
||||||
if !game.downloaded && !game.installed {
|
if !game.downloaded && !game.installed {
|
||||||
// Check if any peers have this game
|
|
||||||
let peer_files_for_game = peer_db.aggregated_game_files(&game.id);
|
let peer_files_for_game = peer_db.aggregated_game_files(&game.id);
|
||||||
|
|
||||||
if peer_files_for_game.is_empty() {
|
if peer_files_for_game.is_empty() {
|
||||||
@@ -536,7 +520,7 @@ async fn update_game_sizes_from_peers(
|
|||||||
if peer_size > 0 {
|
if peer_size > 0 {
|
||||||
game.size = peer_size;
|
game.size = peer_size;
|
||||||
log::debug!(
|
log::debug!(
|
||||||
"Updated size for game {} from peer-reported totals: {} bytes",
|
"Updated size for game {} from peer totals: {} bytes",
|
||||||
game.id,
|
game.id,
|
||||||
peer_size
|
peer_size
|
||||||
);
|
);
|
||||||
@@ -548,16 +532,14 @@ async fn update_game_sizes_from_peers(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log::debug!("No peer size data available for game {}", game.id);
|
log::debug!("No peer size data available for game {}", game.id);
|
||||||
// Keep existing size (will fallback to game.db sizes)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Calculate size from peer majority files
|
|
||||||
let peer_size = calculate_size_from_file_descriptions(&peer_files_for_game);
|
let peer_size = calculate_size_from_file_descriptions(&peer_files_for_game);
|
||||||
|
|
||||||
if peer_size > 0 {
|
if peer_size > 0 {
|
||||||
game.size = peer_size;
|
game.size = peer_size;
|
||||||
log::debug!(
|
log::debug!(
|
||||||
"Updated size for game {} from peer majority files: {} bytes (from {} files)",
|
"Updated size for game {} from peer files: {} bytes ({} files)",
|
||||||
game.id,
|
game.id,
|
||||||
peer_size,
|
peer_size,
|
||||||
peer_files_for_game.len()
|
peer_files_for_game.len()
|
||||||
@@ -702,10 +684,6 @@ async fn update_game_db(games: Vec<Game>, app: AppHandle) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update game sizes from peer data (second priority)
|
|
||||||
// This will update sizes for games that don't have local files but are available from peers
|
|
||||||
update_game_sizes_from_peers(&mut game_db.games, &state.peer_game_db).await;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
refresh_games_list(&app).await;
|
refresh_games_list(&app).await;
|
||||||
|
|||||||
Reference in New Issue
Block a user