python - Google App Engine (Python) 上高度可扩展的标签

标签 python google-app-engine tags high-load microblogging

我有很多(例如)帖子,它们标有一个或多个标签。可以创建或删除帖子,用户也可以对一个或多个标签进行搜索请求(结合逻辑 AND)。 我想到的第一个想法是一个简单的模型

class Post(db.Model):
  #blahblah
  tags = db.StringListProperty()

创建和删除操作的实现是显而易见的。搜索更复杂。要搜索 N 个标签,它会执行 N 个 GQL 查询,例如“SELECT * FROM Post WHERE tags = :1”,并使用游标合并结果,它的性能很糟糕。

第二个想法是将不同实体中的标签分开

class Post(db.Model):
    #blahblah
    tags = db.ListProperty(db.Key) # For fast access

class Tag(db.Model):
    name = db.StringProperty(name="key")
    posts = db.ListProperty(db.Key) # List of posts that marked with tag

它通过键从数据库中获取标签(比通过 GQL 获取标签快得多)并将其合并到内存中,我认为此实现比第一个实现具有更好的性能,但非常频繁使用的标签可能会超过允许的最大大小单个数据存储对象。还有另一个问题:数据存储只能修改一个对象大约 1/秒,因此对于频繁使用的标签,我们也有修改延迟的瓶颈。

有什么建议吗?

最佳答案

为了进一步追问尼克。如果是逻辑 AND 在查询中使用多个标签。使用 tags = tag1 AND tags = tag2 ... 在单个查询中设置成员身份是数据存储区的一大亮点。您可以在一次查询中获得结果。

http://code.google.com/appengine/docs/python/datastore/queriesandindexes.html#Properties_With_Multiple_Values

关于python - Google App Engine (Python) 上高度可扩展的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4280460/

相关文章:

python - BadFilterError : invalid filter: Only one property per query may have inequality filters (<=, >=, <, >)

google-app-engine - IdentityServer4 - 'sub' 声明丢失

python - 使用 App Engine Python 接收非 ascii 电子邮件会导致奇怪的字符编码

latex - 删除 Latex 标签(但不是其内容)的最简单方法?

python - Pyparsing:如何解析数据然后编辑 .txt 文件中的特定值?

python - 在 Ubuntu 上安装 Python 镜像库 (PIL)

Python TkMessageBox 问题不工作!

flash - <object> 标签中的 classid 有什么作用?

html - Sendgrid Newsletter App 自定义标签

python - python 中是否有类似 putAll 的 dict 方法?