Skip to content

Commit

Permalink
Rekindle release with user search & more
Browse files Browse the repository at this point in the history
  • Loading branch information
vthorsteinsson committed Nov 5, 2015
1 parent 8b475ab commit 53510bc
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 35 deletions.
64 changes: 39 additions & 25 deletions admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
from flask import render_template, redirect, jsonify
from flask import request, session, url_for

from google.appengine.ext import ndb
from google.appengine.ext import ndb, deferred

from languages import Alphabet
from skraflgame import User, Game
from skrafldb import Unique, UserModel, GameModel, MoveModel,\
from skrafldb import Context, Unique, UserModel, GameModel, MoveModel,\
FavoriteModel, ChallengeModel, ChannelModel

import netskrafl
Expand All @@ -44,35 +44,49 @@ def admin_usercount():
return jsonify(count = count)


@app.route("/admin/userupdate", methods=['GET'])
def admin_userupdate():
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
q = UserModel.query()
while True:
ulist = []
chunk = 0
for um in q.fetch(CHUNK_SIZE, offset = offset):
chunk += 1
if um.nick_lc == None:
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 == 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:
um.nick_lc = um.nickname.lower()
um.name_lc = um.prefs.get("full_name", "").lower() if um.prefs else ""
ulist.append(um)
ndb.put_multi(ulist)
count += len(ulist)
except Exception as e:
logging.info("Exception in /admin/userupdate 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 /admin/userupdate when updating ndb: {0}".format(e))
if chunk < CHUNK_SIZE:
break
offset += CHUNK_SIZE
return "<html><body><p>Updated {0} user records</p></body></html>".format(count)
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))


@app.route("/admin/userupdate", methods=['GET'])
def admin_userupdate():
""" Start a user update background task """
logging.info("Starting user update")
deferred.defer(deferred_update)
return "<html><body><p>User update started</p></body></html>"


@app.route("/admin/fetchgames", methods=['GET', 'POST'])
Expand Down
4 changes: 2 additions & 2 deletions app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# App.yaml for the Netskrafl application on Google App Engine
#
application: netskrafl
version: rebus
version: rekindle
runtime: python27
api_version: 1
threadsafe: true
Expand Down Expand Up @@ -114,7 +114,7 @@ handlers:
static_files: static/\1
upload: static/.*\.mp3$
mime_type: audio/mpeg
expiration: "1d 0m"
expiration: 1d

# Catchall for noncacheable JavaScript
- url: /static/(.*\.min\.js)$
Expand Down
2 changes: 1 addition & 1 deletion skraflstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
running_local = os.environ.get('SERVER_SOFTWARE','').startswith('Development')

if running_local:
logging.info(u"Netskrafl app running with DEBUG set to True")
logging.info(u"Skraflstats module running with DEBUG set to True")

app.config['DEBUG'] = running_local

Expand Down
4 changes: 0 additions & 4 deletions static/netskrafl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2530,10 +2530,6 @@ function _populateStats(prefix, json) {
var favStar = $("#usr-info-fav-star");
favStar.toggleClass("glyphicon-star-empty", !json.favorite);
favStar.toggleClass("glyphicon-star", json.favorite);
// Show whether a challenge exists between the users
var chall = $("#usr-info-chall");
chall.toggleClass("chall", json.challenge);
chall.toggleClass("no-chall", !json.challenge);
}
// Populate the highest score/best word field
var best = "";
Expand Down
3 changes: 0 additions & 3 deletions templates/board.html
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,6 @@ <h2 id="usr-info-fullname"></h2>
<div class="usr-info-fav" title="Uppáhald">
<span class="glyphicon glyphicon-star" id="usr-info-fav-star"></span>
</div>
<div id="usr-info-chall" class="no-chall" title="Áskorun">
<span class="glyphicon glyphicon-hand-right"></span>
</div>
</div>

<p><strong>Nýjustu viðureignir</strong> <span class="versus-cat"><span class="shown" id="versus-all">gegn öllum</span> <span id="versus-you">gegn þér</span></span></p>
Expand Down

0 comments on commit 53510bc

Please sign in to comment.