コード例 #1
0
ファイル: netskrafl.py プロジェクト: borgar/Skrafl
 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
コード例 #2
0
ファイル: admin.py プロジェクト: tommyy911/Netskrafl
def deferred_update():
    """ Update all users in the datastore with lowercase nick and full name """
    logging.info("Deferred user update starting")
    CHUNK_SIZE = 200
    scan = 0
    count = 0
    with ndb.Client().context():
        try:
            q = UserModel.query()
            for um in iter_q(q, chunk_size=CHUNK_SIZE):
                scan += 1
                if um.email and not um.email.islower():
                    um.email = um.email.lower()
                    um.put()
                    count += 1
                if scan % 1000 == 0:
                    logging.info("Completed scanning {0} and updating {1} user records".format(scan, count))
        except Exception as e:
            logging.info(
                "Exception in deferred_update(): {0}, already scanned {1} records and updated {2}"
                .format(e, scan, count)
            )
            # Do not retry the task
            # !!! TODO: Alternative solution for Python 3 GAE environment
            # raise deferred.PermanentTaskFailure()
    logging.info("Completed scanning {0} and updating {1} user records".format(scan, count))
コード例 #3
0
ファイル: admin.py プロジェクト: magnussig/Netskrafl
def deferred_update():
    """ Update all users in the datastore with lowercase nick and full name """
    logging.info("Deferred user update starting")
    CHUNK_SIZE = 200
    count = 0
    offset = 0
    Context.disable_cache()
    try:
        q = UserModel.query()
        while True:
            ulist = []
            chunk = 0
            for um in q.fetch(CHUNK_SIZE, offset = offset):
                chunk += 1
                if um.nick_lc is None:
                    try:
                        um.nick_lc = um.nickname.lower()
                        um.name_lc = um.prefs.get("full_name", "").lower() if um.prefs else ""
                        ulist.append(um)
                    except Exception as e:
                        logging.info("Exception in deferred_update() when setting nick_lc: {0}".format(e))
            if ulist:
                try:
                    ndb.put_multi(ulist)
                    count += len(ulist)
                except Exception as e:
                    logging.info("Exception in deferred_update() when updating ndb: {0}".format(e))
            if chunk < CHUNK_SIZE:
                break
            offset += CHUNK_SIZE
    except Exception as e:
        logging.info("Exception in deferred_update(): {0}, already updated {1} records".format(e, count))
        # Do not retry the task
        raise deferred.PermanentTaskFailure()
    logging.info("Completed updating {0} user records".format(count))
コード例 #4
0
ファイル: skraflgame.py プロジェクト: rtolsson/Netskrafl
    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)
コード例 #5
0
ファイル: skraflgame.py プロジェクト: gitter-badger/Netskrafl
    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)
コード例 #6
0
ファイル: admin.py プロジェクト: withrocks/Netskrafl
def deferred_update():
    """ Update all users in the datastore with lowercase nick and full name """
    logging.info("Deferred user update starting")
    CHUNK_SIZE = 200
    count = 0
    offset = 0
    Context.disable_cache()
    try:
        q = UserModel.query()
        while True:
            ulist = []
            chunk = 0
            for um in q.fetch(CHUNK_SIZE, offset = offset):
                chunk += 1
                if um.nick_lc is None:
                    try:
                        um.nick_lc = um.nickname.lower()
                        um.name_lc = um.prefs.get("full_name", "").lower() if um.prefs else ""
                        ulist.append(um)
                    except Exception as e:
                        logging.info("Exception in deferred_update() when setting nick_lc: {0}".format(e))
            if ulist:
                try:
                    ndb.put_multi(ulist)
                    count += len(ulist)
                except Exception as e:
                    logging.info("Exception in deferred_update() when updating ndb: {0}".format(e))
            if chunk < CHUNK_SIZE:
                break
            offset += CHUNK_SIZE
    except Exception as e:
        logging.info("Exception in deferred_update(): {0}, already updated {1} records".format(e, count))
        # Do not retry the task
        raise deferred.PermanentTaskFailure()
    logging.info("Completed updating {0} user records".format(count))
コード例 #7
0
ファイル: skraflgame.py プロジェクト: s31415/Netskrafl
 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
コード例 #8
0
ファイル: skraflstats.py プロジェクト: magnussig/Netskrafl
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)
コード例 #9
0
ファイル: skraflstats.py プロジェクト: withrocks/Netskrafl
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)
コード例 #10
0
ファイル: skraflgame.py プロジェクト: gitter-badger/Netskrafl
 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
コード例 #11
0
ファイル: admin.py プロジェクト: halldorel/Netskrafl
def admin_usercount():
    """ Return a count of UserModel entities """
    count = UserModel.count()
    return jsonify(count = count)
コード例 #12
0
ファイル: admin.py プロジェクト: tommyy911/Netskrafl
def admin_usercount():
    """ Return a count of UserModel entities """
    count = UserModel.count()
    return jsonify(count=count)
コード例 #13
0
ファイル: netskrafl.py プロジェクト: borgar/Skrafl
 def update(self):
     UserModel.update(self._user_id, self._nickname, self._inactive, self._preferences)