Permalink
Browse files

Stop invalidating the all portals cache, to decrease datastore read o…

…perations
  • Loading branch information...
1 parent 9ad71e1 commit 5911637da7531e1be7c4af424287be76f9b2d221 @metzen committed Dec 19, 2012
Showing with 7 additions and 2 deletions.
  1. +7 −2 server/main.py
View
@@ -91,7 +91,7 @@ def get(self):
logging.info('Pulling portals from datastore')
portals_json = json.dumps(
portals_query.run(batch_size=1000), cls=PortalJSONEncoder)
- memcache.set('portals', portals_json)
+ memcache.set(key, portals_json)
self.response.out.write(")]}',\n" + portals_json)
@@ -105,7 +105,12 @@ def put(self, lat, lng):
kwargs['address'] = util.lookup_address(lat, lng)
portal, created = models.Portal.get_or_insert(added_by=self.user, **kwargs)
if created:
- memcache.delete('portals')
+ # Add it to the cached JSON list of all portals.
+ portals_json = memcache.get('portals')
+ if portals_json is not None:
+ portals = json.loads(portals_json)
+ portals.append(portal)
+ memcache.set('portals', json.dumps(portals, cls=PortalJSONEncoder))
if kwargs.get('watched'):
xmpp.send_invite(self.user.email)
if self.user.key() not in portal.subscribers:

0 comments on commit 5911637

Please sign in to comment.