Wait for datastore update before proceeding

2019-08-15 20:00发布

I'm working on a lightweight app, and I have quite a few situations where the user submits a form, the form data is processed and pushed to the datastore, and then the user is redirected to a page that displays some of the same data. It's quite often the case that the user gets to the page before the datastore has been updated, so they see old data. Is there any way to have the app wait for the datastore to update before proceeding? The obvious hacky solution is calling sleep(1), but that's obviously not ideal and takes longer than the actual update.

1条回答
倾城 Initia
2楼-- · 2019-08-15 20:32

Just get the key the .put() returns:

key = mything.put()

and pass it on to the other page (e.g via urlsafe). The other page can rebuild the key and then

thething = key.get()

will always give you updated data -- i.e, this (key.get()) is one simple way to get strong consistency from the GAE datastore!

查看更多
登录 后发表回答