peer count for all games
This commit is contained in:
@@ -204,6 +204,16 @@ impl PeerGameDB {
|
||||
#[must_use]
|
||||
pub fn get_all_games(&self) -> Vec<Game> {
|
||||
let mut aggregated: HashMap<String, Game> = HashMap::new();
|
||||
let mut peer_counts: HashMap<String, u32> = HashMap::new();
|
||||
|
||||
// Count peers per game
|
||||
for peer in self.peers.values() {
|
||||
for game_id in peer.games.keys() {
|
||||
*peer_counts.entry(game_id.clone()).or_insert(0) += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Aggregate games with peer counts
|
||||
for peer in self.peers.values() {
|
||||
for game in peer.games.values() {
|
||||
aggregated
|
||||
@@ -218,8 +228,14 @@ impl PeerGameDB {
|
||||
} else if existing.eti_game_version.is_none() {
|
||||
existing.eti_game_version.clone_from(&game.eti_game_version);
|
||||
}
|
||||
// Update peer count
|
||||
existing.peer_count = peer_counts[&game.id];
|
||||
})
|
||||
.or_insert_with(|| game.clone());
|
||||
.or_insert_with(|| {
|
||||
let mut game_clone = game.clone();
|
||||
game_clone.peer_count = peer_counts[&game.id];
|
||||
game_clone
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1109,6 +1125,7 @@ async fn load_local_game_db(game_dir: &str) -> eyre::Result<GameDB> {
|
||||
installed: true,
|
||||
eti_game_version: version.clone(),
|
||||
local_version: version,
|
||||
peer_count: 0, // Local games start with 0 peers
|
||||
};
|
||||
games.push(game);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user