def deletePlayer(cls, playerId): player = Player.get_by_id(playerId, parent=None) parentGame = Game.get_by_id(player.parentId) parentGame.playerIds.remove(playerId) parentGame.put() memcache.delete(str(playerId), namespace='players') player.key.delete()
def getPlayersForGame(cls, gameId): game = Game.get_by_id(int(gameId)); # Initialize string representations of player and entity IDs game.makeStringValuedIds() # Get all cached buddies buddyDictionary = memcache.get_multi( game.playerIdStrings, key_prefix='player' ) # Go through all buddy-keys of the parent game for playerId in game.playerIdStrings: # if one is missing, reload from the database and add to the buddy dictionary if playerId not in buddyDictionary: buddyDictionary[playerId] = Player.get_by_id( int(playerId), parent=None ) # Now we're sure everybody is there. No Child Left Behind. # Everybody is in the dictionary. A good time to write it to the cache again memcache.set_multi(buddyDictionary) # The caller is only interested in the values of the dictionary. return buddyDictionary.values()
def getPlayersForGame(cls, gameId): game = Game.get_by_id(int(gameId)) # Initialize string representations of player and entity IDs game.makeStringValuedIds() # Get all cached buddies buddyDictionary = memcache.get_multi(game.playerIdStrings, key_prefix='player') # Go through all buddy-keys of the parent game for playerId in game.playerIdStrings: # if one is missing, reload from the database and add to the buddy dictionary if playerId not in buddyDictionary: buddyDictionary[playerId] = Player.get_by_id(int(playerId), parent=None) # Now we're sure everybody is there. No Child Left Behind. # Everybody is in the dictionary. A good time to write it to the cache again memcache.set_multi(buddyDictionary) # The caller is only interested in the values of the dictionary. return buddyDictionary.values()
def getGameForPlayer(cls, playerId): player = Player.get_by_id(playerId, parent=None) return Game.get_by_id(player.parentId, parent=None)
def getById(cls, id): return Game.get_by_id(id, parent=None)