Skip to content

Commit

Permalink
Only compute displayed rating if enforcement is enabled
Browse files Browse the repository at this point in the history
This should significantly reduce calls to rating initialization code
  • Loading branch information
Askaholic committed Sep 24, 2021
1 parent 474bb1f commit ad6fa38
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 8 additions & 3 deletions server/games/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,17 +861,22 @@ def report_army_stats(self, stats_json):
self._process_pending_army_stats()

def is_visible_to_player(self, player: Player) -> bool:
"""
Determine if a player should see this game in their games list.
Note: This is a *hot* function, it can have significant impacts on
performance.
"""
if self.host is None:
return False

if player == self.host or player in self._connections:
return True

mean, dev = player.ratings[self.rating_type]
displayed_rating = mean - 3 * dev
if (
self.enforce_rating_range
and displayed_rating not in self.displayed_rating_range
and player.get_displayed_rating(self.rating_type)
not in self.displayed_rating_range
):
return False

Expand Down
4 changes: 4 additions & 0 deletions server/players.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ def faction(self, value: Union[str, int, Faction]) -> None:
else:
self._faction = Faction.from_value(value)

def get_displayed_rating(self, rating_type: str) -> float:
mean, dev = self.ratings[rating_type]
return mean - 3 * dev

def power(self) -> int:
"""An artifact of the old permission system. The client still uses this
number to determine if a player gets a special category in the user list
Expand Down

0 comments on commit ad6fa38

Please sign in to comment.