使用2级注释获取和输出内容的最有效方法是什么?

时间:2010-03-29 20:53:25

标签: google-app-engine performance comments

我有一些内容,最多有2个级别的回复。我想知道获取和输出回复的最有效方法是什么。我应该注意,我计划使用字段content_idreply_to存储评论,其中reply_to指的是回复的评论(如果有的话)。对此设计的任何批评都是受欢迎的。

在伪代码(ish)中,我的第一次尝试是:

# in outputting content CONTENT_ID
all_comments = fetch all comments where content_id == CONTENT_ID
root_comments =  filter all_comments with reply_to == None
children_comments = filter all_comments with reply_to != None

output_comments = list()
for each root_comment
    children = filter children_comments, reply_to == root_comment.id
    output_coments.append( (root_comment, children) )

send output_comments to template

这是最好的方法吗?提前谢谢。

编辑:第二个想法,我想在评论中保留日期顺序,所以我必须做一些不同的事情,或者至少只是对评论进行排序。

1 个答案:

答案 0 :(得分:1)

如果您要显示所有注释,只需在一次操作中获取所有注释,然后在Python中构建树。

相关问题