python - Google App Engine 上论坛应用程序的数据建模建议

标签 python google-app-engine data-modeling

我正在 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()

其次,我很确定您应该使用任何它有效且更具可读性的东西,并在以后测试性能,原因有以下三个:

  1. KISS(保持简单)
  2. 早期优化不好
  3. 无法衡量就无法改进

因此,当您准备好测量时,请开始优化。

我这么说并不是因为我对 RDBMS、No-SQL DBMS 或 Google Datastore 性能优化一无所知,而是因为我通常从测试中获得所有关于它的知识,这似乎更经常地与之前的假设相矛盾超出我的预期。

关于python - Google App Engine 上论坛应用程序的数据建模建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2079763/

相关文章:

sql - 糟糕的数据库模式设计的升级策略

nosql - Cassandra 数据模型

python - 如何在多索引数据帧上同时执行两个切片?

python - 如何为 Google Cloud Endpoints 方法生成 pydoc 文档?

java - 在 GAE 中使用 Log4j 2 的问题

asp.net - 如何在 Google App Engine 上托管 ASP.NET MVC 5.1 应用程序

mysql - 第四个表中三个表之间的关系模型

python - 如何通过 WxPython 使用标准工具栏图标?

Python 无法验证 SSL/TLS 连接的任何 CRL

python - 如何在 pyspark 中对 A1、A2、A10 等 ID 进行排序?