Ejemplo n.º 1
0
    def update(self):
        """ Update the user's record in the database and in the memcache """
        with User._lock:
            # Use a lock to avoid the scenaro where a user is fetched by another
            # request in the interval between a database update and a memcache update
            um = UserModel.fetch(self._user_id)
            assert um is not None
            um.nickname = self._nickname
            um.nick_lc = self._nickname.lower()
            um.name_lc = self.full_name().lower()
            um.inactive = self._inactive
            um.prefs = self._preferences
            um.ready = self._ready
            um.ready_timed = self._ready_timed
            um.elo = self._elo
            um.human_elo = self._human_elo
            um.highest_score = self._highest_score
            um.highest_score_game = self._highest_score_game
            um.best_word = self._best_word
            um.best_word_score = self._best_word_score
            um.best_word_game = self._best_word_game
            um.put()

            # Note: the namespace version should be incremented each time
            # that the class properties change
            memcache.set(self._user_id, self, time=User._CACHE_EXPIRY, namespace=User._NAMESPACE)
Ejemplo n.º 2
0
    def update(self):
        """ Update the user's record in the database and in the memcache """
        with User._lock:
            # Use a lock to avoid the scenaro where a user is fetched by another
            # request in the interval between a database update and a memcache update
            um = UserModel.fetch(self._user_id)
            assert um is not None
            um.nickname = self._nickname
            um.nick_lc = self._nickname.lower()
            um.name_lc = self.full_name().lower()
            um.inactive = self._inactive
            um.prefs = self._preferences
            um.ready = self._ready
            um.ready_timed = self._ready_timed
            um.elo = self._elo
            um.human_elo = self._human_elo
            um.highest_score = self._highest_score
            um.highest_score_game = self._highest_score_game
            um.best_word = self._best_word
            um.best_word_score = self._best_word_score
            um.best_word_game = self._best_word_game
            um.put()

            # Note: the namespace version should be incremented each time
            # that the class properties change
            memcache.set(self._user_id,
                         self,
                         time=User._CACHE_EXPIRY,
                         namespace=User._NAMESPACE)
Ejemplo n.º 3
0
 def fetch(self):
     u = UserModel.fetch(self._user_id)
     if u is None:
         UserModel.create(self._user_id, self.nickname())
         # Use the default properties for a newly created user
         return
     self._nickname = u.nickname
     self._inactive = u.inactive
     self._preferences = u.prefs
Ejemplo n.º 4
0
 def _fetch(self):
     """ Fetch the user's record from the database """
     um = UserModel.fetch(self._user_id)
     if um is None:
         # Use the default properties for a newly created user
         UserModel.create(self._user_id, self.nickname()) # This updates the database
     else:
         # Obtain the properties from the database entity
         self._nickname = um.nickname
         self._inactive = um.inactive
         self._preferences = um.prefs
         self._ready = um.ready
         self._ready_timed = um.ready_timed
         self._elo = um.elo
         self._human_elo = um.human_elo
         self._highest_score = um.highest_score
         self._highest_score_game = um.highest_score_game
         self._best_word = um.best_word
         self._best_word_score = um.best_word_score
         self._best_word_game = um.best_word_game
Ejemplo n.º 5
0
def _write_stats(timestamp, urecs):
    """ Writes the freshly calculated statistics records to the database """
    # Delete all previous stats with the same timestamp, if any
    StatsModel.delete_ts(timestamp = timestamp)
    um_list = []
    for sm in urecs.values():
        # Set the reference timestamp for the entire stats series
        sm.timestamp = timestamp
        # Fetch user information to update Elo statistics
        if sm.user:
            # Not robot
            um = UserModel.fetch(sm.user.id())
            if um:
                um.elo = sm.elo
                um.human_elo = sm.human_elo
                um_list.append(um)
    # Update the statistics records
    StatsModel.put_multi(urecs.values())
    # Update the user records
    UserModel.put_multi(um_list)
Ejemplo n.º 6
0
def _write_stats(timestamp, urecs):
    """ Writes the freshly calculated statistics records to the database """
    # Delete all previous stats with the same timestamp, if any
    StatsModel.delete_ts(timestamp=timestamp)
    um_list = []
    for sm in urecs.values():
        # Set the reference timestamp for the entire stats series
        sm.timestamp = timestamp
        # Fetch user information to update Elo statistics
        if sm.user:
            # Not robot
            um = UserModel.fetch(sm.user.id())
            if um:
                um.elo = sm.elo
                um.human_elo = sm.human_elo
                um_list.append(um)
    # Update the statistics records
    StatsModel.put_multi(urecs.values())
    # Update the user records
    UserModel.put_multi(um_list)
Ejemplo n.º 7
0
 def _fetch(self):
     """ Fetch the user's record from the database """
     um = UserModel.fetch(self._user_id)
     if um is None:
         # Use the default properties for a newly created user
         self.set_new_bag(True)  # Fresh users get the new bag by default
         UserModel.create(self._user_id, self.nickname(),
                          self._preferences)  # This updates the database
     else:
         # Obtain the properties from the database entity
         self._nickname = um.nickname
         self._inactive = um.inactive
         self._preferences = um.prefs
         self._ready = um.ready
         self._ready_timed = um.ready_timed
         self._elo = um.elo
         self._human_elo = um.human_elo
         self._highest_score = um.highest_score
         self._highest_score_game = um.highest_score_game
         self._best_word = um.best_word
         self._best_word_score = um.best_word_score
         self._best_word_game = um.best_word_game