Wait for datastore update before proceeding

百般思念 提交于 2019-12-11 10:37:36

问题


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:


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!



来源:https://stackoverflow.com/questions/28935423/wait-for-datastore-update-before-proceeding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!