我正在 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
...
最佳答案
首先,为什么不使用 user = db.UserProperty()
而不是 user = db.StringProperty()
?
其次,我很确定您应该使用任何它有效且更具可读性的东西,并在以后测试性能,原因有以下三个:
- KISS(保持简单)
- 早期优化不好
- 无法衡量就无法改进
因此,当您准备好测量时,请开始优化。
我这么说并不是因为我对 RDBMS、No-SQL DBMS 或 Google Datastore 性能优化一无所知,而是因为我通常从测试中获得所有关于它的知识,这似乎更经常地与之前的假设相矛盾超出我的预期。
关于python - Google App Engine 上论坛应用程序的数据建模建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2079763/