<commit_before>import UserDict
import threading

import hlib.pageable

import lib.datalayer

# pylint: disable-msg=F0401
import hruntime

class PlayerStatsWrapper(UserDict.UserDict):
  def default(self, key):
    return None

  def __getitem__(self, key):
    if key not in self.data:
      return self.default(key)

    return UserDict.UserDict.__getitem__(self, key)

class Stats(hlib.pageable.Pageable):
  def __init__(self, *args, **kwargs):
    super(Stats, self).__init__(*args, **kwargs)

    self.lock		= threading.RLock()

    self._stats		= None
    self._player_stats	= None

    self.last_update	= None

  def __getattr__(self, name):
    if name == 'records' or name == 'player_stats':
      with self.lock:
        if not self._stats:
          self.refresh_stats()

        if name == 'records':
          return self._records

        if name == 'player_stats':
          return self._player_stats

    return super(Stats, self).__getattr__(name)

  def refresh_stats(self):
    with self.lock:
      self.last_update = hruntime.time
      hruntime.cache.remove_for_all_users('stats')<commit_msg>Games' stats were not cached<commit_after>import UserDict
import threading

import hlib.pageable

import lib.datalayer

# pylint: disable-msg=F0401
import hruntime

class PlayerStatsWrapper(UserDict.UserDict):
  def default(self, key):
    return None

  def __getitem__(self, key):
    if key not in self.data:
      return self.default(key)

    return UserDict.UserDict.__getitem__(self, key)

class Stats(hlib.pageable.Pageable):
  def __init__(self, *args, **kwargs):
    super(Stats, self).__init__(*args, **kwargs)

    self.lock		= threading.RLock()

    self._records		= None
    self._player_stats	= None

    self.last_update	= None

  def __getattr__(self, name):
    if name == 'records' or name == 'player_stats':
      with self.lock:
        if not self._records:
          self.refresh_stats()

        if name == 'records':
          return self._records

        if name == 'player_stats':
          return self._player_stats

    return super(Stats, self).__getattr__(name)

  def refresh_stats(self):
    with self.lock:
      self.last_update = hruntime.time
      hruntime.cache.remove_for_all_users('stats')
{'fraction_non_alphanumeric': 0.10477039679001338, 'fraction_numerical': 0.0035666518056174765, 'mean_word_length': 3.132596685082873, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4075403', 'n_tokens_mistral': 735, 'n_tokens_neox': 706, 'n_words': 171}