Index: wto-informals.py =================================================================== --- wto-informals.py (revision 5) +++ wto-informals.py (working copy) @@ -10,6 +10,32 @@ from google.appengine.ext import webapp from google.appengine.ext import db + +cache_hits = 0; +# dictionary from group name to member list +group_members_cache = None +member_groups_cache = None + +def build_cache(): + global group_members_cache, member_groups_cache + + if not group_members_cache or not member_groups_cache: + logging.info("building cache.") + temp_group_members_cache = {} + temp_member_groups_cache = {} + + memberships = Membership.all() + for membership in memberships: + # TODO use db keys instead of name and iso? + iso = membership.member.iso + name = membership.group.name + temp_group_members_cache.setdefault(name, []).append(iso) + temp_member_groups_cache.setdefault(iso, []).append(name) + + group_members_cache = temp_group_members_cache + member_groups_cache = temp_member_groups_cache + logging.info("Cache built.") + # Model Classes # #___________________# @@ -74,7 +100,7 @@ self.response.out.write(simplejson.dumps(result)) class MemberDetails(webapp.RequestHandler): - def get(self): + def get(self, group): members = Member.all() result = [member for member in members] self.response.out.write(simplejson.dumps(result)) @@ -91,14 +117,24 @@ class GroupList(webapp.RequestHandler): def get(self): - groups = Groups.all() - result = [group.name for group in groups] + groups = Group.all() + result = [group.name for group in groups if group.active] self.response.out.write(simplejson.dumps(result)) class GroupDetails(webapp.RequestHandler): def get(self): + global group_members_cache + groups = Group.all() - result = [group for group in groups] + result = [] + for group in groups: + result.append( { + "formal_name": group.formal_name, + "created": str(group.created), + "name": group.name, + "active": group.active, + "members": group_members_cache.get(group.name, []) + }) self.response.out.write(simplejson.dumps(result)) class GroupMembers(webapp.RequestHandler): @@ -147,12 +183,29 @@ #if not curUser: # self.redirect(users.create_login_url(self.request.uri)) # return + + TAGLINES = [ + "tracking the meetings between the meetings", + "tracking the meetings between the meetings", + "tracking the meetings between the meetings", + "possibly the coolest map on the internet", + "you probably didn't even know there was such a thing", + "where the secret cabals make nefarious decisions", + "this is what international trade nerds do with free time", + ] + + data = { + "tagline": TAGLINES[random.randint(0, len(TAGLINES) - 1)] + } path = os.path.join(os.path.dirname(__file__), 'templates/browser.html') - self.response.out.write(template.render(path, None)) + self.response.out.write(template.render(path, data)) def main(): + global cache_hits + cache_hits += 1 + build_cache() application = webapp.WSGIApplication( [ ('/', RootPage),