使用 GAE 数据存储进行作业管理
我的数据存储中有一个“计算”实体,该实体下有 700 万个对象。它具有以下属性(python 运行时):
class Calculation(db.Model):
question = db.StringProperty(required=True)
answer = db.StringProperty()
假设“question”属性的示例是“1+1”、“2+2”、“3+3”(不是很重要)。所有计算对象都以空答案属性开始。
当用户连接到应用程序时,会进行 ajax 调用,我的应用程序应该 [1] 获取具有空答案属性的 Calculation 对象并将其发送到用户的浏览器。然后,用户的浏览器评估问题并将其发送回不同的服务器处理程序。
如何更新特定计算对象的答案属性[2]?
如果有人能为我提供 [1] 和 [2] 的代码,那就太好了。对 App Engine 没有真正的经验,而且查询内容很混乱。如果我想尽可能节省服务器 CPU,最佳解决方案是什么?
谢谢!
I have a 'Calculation' entity in my datastore with say, 7 million objects under that entity. It has the following properties (python runtime):
class Calculation(db.Model):
question = db.StringProperty(required=True)
answer = db.StringProperty()
suppose examples of the 'question' property are things like '1+1', '2+2', '3+3' (not really important). All the calculation objects start out with empty answer properties.
When a user connects to the app, an ajax call is made and my app is supposed to [1] fetch a Calculation object with an empty answer property and send it to the user's browser. The user's browser then evaluates the question and sends it back to a different server handler.
How do I update that specific Calculation object's answer property[2]?
If someone could provide me with code for [1] and [2] that would be great. Not really experienced with App Engine and the query stuff is confusing. What is the best solution for this if I want to conserve as much server-CPU as possible?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道我是否真正理解了。但您只需为第一个 ajax 调用返回实体计算的键和
问题
。当用户做出响应时,您首先通过键获取实体并更新属性answer
。步骤 1,ajax 调用返回 JSON 格式的问题(例如):
步骤 2,通过键更新实体:
I don't know if i have really understand. But you simply need to return for your first ajax call the key of the entity Calculation and the
question
. When the user makes a response you firstly get the entity by the key and update the propertyanswer
.Step 1, The ajax call return a question in JSON (for example):
Step 2, You update the entity by the key: