简体   繁体   English

使用Python在Google Appengine上创建线程注释的模型

[英]Model to create threaded comments on Google Appengine with Python

I am trying to write a comments model which can be threaded (no limits to the number of child threads). 我试图编写一个可以线程化的注释模型(子线程数没有限制)。 How do I do this in Appengine? 如何在Appengine中执行此操作? and what is the fastest way to read all comments? 阅读所有评论的最快方法是什么?

I am trying to do this in a scalable way so that app engine's new pricing does not kill my startup :) 我正在尝试以可扩展的方式执行此操作,以使应用程序引擎的新定价不会扼杀我的创业公司:)

It depends on how nested threads you expect to get and if you want to optimize reading or writing. 这取决于您期望如何获得嵌套线程,以及是否要优化读取或写入。 If we guess that the threads normally are quite shallow and that you want to optimize reading all subcomments on all levels of a comment, I think you should store each comment in a separate entry and then put a reference to it in a list on the parent and the parent's parent and so forth. 如果我们猜想线程通常很浅并且您想优化读取注释的所有级别上的所有子注释,那么我认为您应该将每个注释存储在单独的条目中,然后在父列表中放置对它的引用以及父母的父母等等。

That way getting all subcomments are always just one call, but writing a new comment is a bit slower, since you have to modify all parents. 这样,获取所有子注释始终只是一个调用,但是编写新注释要慢一些,因为您必须修改所有父注释。

If you need fast way to read all comments, keep in comment model not only a reference to the parent comment but add a reference to the whole topic also. 如果您需要快速的方式来读取所有评论,则在评论模型中不仅要保留对父评论的引用,还应添加对整个主题的引用。 Then you will be able to get all comments for the topic with Comment.query(Comment.topic=12334).fetch() . 然后,您将可以通过Comment.query(Comment.topic=12334).fetch()获得该主题的所有评论。

If you are worrying about datastore usage cost use http://code.google.com/p/appengine-ndb-experiment/ . 如果您担心数据存储区的使用成本,请使用http://code.google.com/p/appengine-ndb-experiment/ It allows to use reduce saved data amount and number of queries. 它允许使用减少保存的数据量和查询数量。 Shortly it will replace current db module. 不久它将替换当前的db模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM