def upsert_comment_chain(mongo, identifier, recursive=False):
""" Upsert given comments and its parent(s).
Args:
mongo: mongodb instance
identifier: Post identifier
recursive: (Defaults to False). If True, recursively update all parent comments, incl. root post.
"""
with suppress(PostDoesNotExist):
p = Post(identifier)
if p.is_comment():
mongo.Comments.update({'identifier': p.identifier}, p.export(), upsert=True)
parent_identifier = '@%s/%s' % (p.parent_author, p.parent_permlink)
if recursive:
upsert_comment_chain(mongo, parent_identifier, recursive)
else:
upsert_comment(mongo, parent_identifier)
else:
return mongo.Posts.update({'identifier': p.identifier}, p.export(), upsert=True)
评论列表
文章目录