Optimize var.get_role
It will now return as soon as it finds the role for the player, instead of calling var.list_players_and_roles every single time. I haven't tested in a real-world scenario, but in a test game with 10000 players (don't ask), the speed improvement is very clear (~1-2s per player when sending out nighttime PMs instead of ~10s).
This commit is contained in:
parent
ad26f0b693
commit
b968f83e8b
@ -345,7 +345,12 @@ def list_players_and_roles():
|
|||||||
plr[p] = x
|
plr[p] = x
|
||||||
return plr
|
return plr
|
||||||
|
|
||||||
get_role = lambda plyr: list_players_and_roles()[plyr]
|
def get_role(p):
|
||||||
|
for role, pl in ROLES.items():
|
||||||
|
if role in TEMPLATE_RESTRICTIONS.keys():
|
||||||
|
continue # only get actual roles
|
||||||
|
if p in pl:
|
||||||
|
return role
|
||||||
|
|
||||||
def get_reveal_role(nick):
|
def get_reveal_role(nick):
|
||||||
if HIDDEN_TRAITOR and get_role(nick) == "traitor":
|
if HIDDEN_TRAITOR and get_role(nick) == "traitor":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user