From b249c5377e7bcfc81d02d21daee48c174541a820 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Thu, 26 Feb 2015 14:47:15 +0700 Subject: [PATCH] nitrpg: implement correct caching for User::player Signed-off-by: Jean Privat --- contrib/nitrpg/src/game.nit | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/contrib/nitrpg/src/game.nit b/contrib/nitrpg/src/game.nit index 9c71566..4d62283 100644 --- a/contrib/nitrpg/src/game.nit +++ b/contrib/nitrpg/src/game.nit @@ -235,11 +235,16 @@ end redef class User # The player linked to `self`. - fun player(game: Game): Player is lazy do - var player = game.load_player(login) + fun player(game: Game): Player do + var player = player_cache.get_or_null(game) + if player != null then return player + player = game.load_player(login) if player == null then player = game.add_player(self) + player_cache[game] = player return player end + + private var player_cache = new HashMap[Game, Player] end # A GameReactor reacts to event sent by a `Github::HookListener`. -- 1.7.9.5