【发布时间】:2011-01-05 23:46:39
【问题描述】:
我正在 Google App Engine 上编写一个类似论坛的简单应用程序,并试图避免可扩展性问题。我是这种非 RBDMS 方法的新手,我想从一开始就避免陷阱。
论坛设计非常简单,帖子和回复将是唯一的概念。如果论坛有数百万个帖子,那么解决问题的最佳方法是什么?
目前的模型(去除了无用的属性):
class Message(db.Model):
user = db.StringProperty() # will be a google account user_id
text = db.TextProperty() # the text of the message
reply_to = db.SelfReferenceProperty() # if null is a post, if not null a reply (useful for reply-to-reply)
拆分模型,我认为它更快,因为它会在检索“所有帖子”时查询更少的项目:
class Post(db.Model):
user = db.StringProperty() # will be a google account user_id
text = db.TextProperty() # the text of the message
class Reply(db.Model):
user = db.StringProperty() # will be a google account user_id
text = db.TextProperty() # the text of the message
reply_to = db.ReferenceProperty(Post)
这是 RDBMS 世界中的多对一关系,应该使用 ListProperty 代替吗?如果有,怎么做?
编辑:
Jaiku 使用类似的东西
class StreamEntry(DeletedMarkerModel):
...
entry = models.StringProperty() # ref - the parent of this, should it be a comment
...
【问题讨论】:
-
我假设您可以回复回复?如果可以的话,这将不会真正有效地工作......
标签: python google-app-engine data-modeling