当前位置: 首页>>代码示例>>Python>>正文


Python CommentTree.rebuild方法代码示例

本文整理汇总了Python中r2.models.comment_tree.CommentTree.rebuild方法的典型用法代码示例。如果您正苦于以下问题:Python CommentTree.rebuild方法的具体用法?Python CommentTree.rebuild怎么用?Python CommentTree.rebuild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在r2.models.comment_tree.CommentTree的用法示例。


在下文中一共展示了CommentTree.rebuild方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: rebuild_comment_tree

# 需要导入模块: from r2.models.comment_tree import CommentTree [as 别名]
# 或者: from r2.models.comment_tree.CommentTree import rebuild [as 别名]
def rebuild_comment_tree(link, timer):
    with CommentTree.mutation_context(link, timeout=180):
        timer.intermediate('lock')
        cache = CommentTree.rebuild(link)
        timer.intermediate('rebuild')
        # the tree rebuild updated the link's comment count, so schedule it for
        # search reindexing
        link.update_search_index()
        timer.intermediate('update_search_index')
        return cache
开发者ID:Omosofe,项目名称:reddit,代码行数:12,代码来源:comment_tree.py

示例2: get_comment_tree

# 需要导入模块: from r2.models.comment_tree import CommentTree [as 别名]
# 或者: from r2.models.comment_tree.CommentTree import rebuild [as 别名]
def get_comment_tree(link, _update=False, timer=None):
    if timer is None:
        timer = SimpleSillyStub()
    cache = CommentTree.by_link(link)
    timer.intermediate('load')
    if cache and not _update:
        return cache
    with CommentTree.mutation_context(link, timeout=180):
        timer.intermediate('lock')
        cache = CommentTree.rebuild(link)
        timer.intermediate('rebuild')
        # the tree rebuild updated the link's comment count, so schedule it for
        # search reindexing
        link.update_search_index()
        timer.intermediate('update_search_index')
        return cache
开发者ID:Matthew94,项目名称:reddit,代码行数:18,代码来源:comment_tree.py

示例3: get_comment_tree

# 需要导入模块: from r2.models.comment_tree import CommentTree [as 别名]
# 或者: from r2.models.comment_tree.CommentTree import rebuild [as 别名]
def get_comment_tree(link, _update=False, timer=None):
    if timer is None:
        timer = SimpleSillyStub()
    cache = CommentTree.by_link(link)
    timer.intermediate("load")
    if cache and not _update:
        return cache
    with CommentTree.mutation_context(link, timeout=180):
        timer.intermediate("lock")
        cache = CommentTree.rebuild(link)
        timer.intermediate("rebuild")
        # the tree rebuild updated the link's comment count, so schedule it for
        # search reindexing
        from r2.lib.db.queries import changed

        changed([link])
        timer.intermediate("changed")
        return cache
开发者ID:rasher,项目名称:reddit,代码行数:20,代码来源:comment_tree.py

示例4: add_comments

# 需要导入模块: from r2.models.comment_tree import CommentTree [as 别名]
# 或者: from r2.models.comment_tree.CommentTree import rebuild [as 别名]
def add_comments(comments):
    """Add comments to the CommentTree and update scores."""
    from r2.models.builder import write_comment_orders

    link_ids = [comment.link_id for comment in tup(comments)]
    links = Link._byID(link_ids, data=True)

    comments = tup(comments)
    comments_by_link_id = defaultdict(list)
    for comment in comments:
        comments_by_link_id[comment.link_id].append(comment)

    for link_id, link_comments in comments_by_link_id.iteritems():
        link = links[link_id]

        new_comments = [
            comment for comment in link_comments if not comment._deleted]
        deleted_comments = [
            comment for comment in link_comments if comment._deleted]
        timer = g.stats.get_timer(
            'comment_tree.add.%s' % link.comment_tree_version)
        timer.start()

        # write scores before CommentTree because the scores must exist for all
        # comments in the tree
        for sort in ("_controversy", "_confidence", "_score"):
            scores_by_comment = {
                comment._id36: getattr(comment, sort)
                for comment in link_comments
            }
            CommentScoresByLink.set_scores(link, sort, scores_by_comment)

        scores_by_comment = _get_qa_comment_scores(link, link_comments)
        CommentScoresByLink.set_scores(link, "_qa", scores_by_comment)
        timer.intermediate('scores')

        with CommentTree.mutation_context(link, timeout=180):
            try:
                timer.intermediate('lock')
                comment_tree = CommentTree.by_link(link, timer)
                timer.intermediate('get')

                if new_comments:
                    comment_tree.add_comments(new_comments)

                for comment in deleted_comments:
                    comment_tree.delete_comment(comment, link)

                timer.intermediate('update')
            except InconsistentCommentTreeError:
                # this exception occurs when we add a comment to the tree but
                # its parent isn't in the tree yet, need to rebuild the tree
                # from scratch

                comment_ids = [comment._id for comment in link_comments]
                g.log.exception(
                    'add_comments_nolock failed for link %s %s, recomputing',
                    link_id, comment_ids)

                comment_tree = CommentTree.rebuild(link)
                timer.intermediate('rebuild')
                # the tree rebuild updated the link's comment count, so schedule
                # it for search reindexing
                link.update_search_index()
                timer.intermediate('update_search_index')
                g.stats.simple_event('comment_tree_inconsistent')

            # do this under the same lock because we want to ensure we are using
            # the same version of the CommentTree as was just written
            write_comment_orders(link, timer)
            timer.intermediate('write_order')

        timer.stop()
开发者ID:mishalzaman,项目名称:reddit,代码行数:75,代码来源:comment_tree.py


注:本文中的r2.models.comment_tree.CommentTree.rebuild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。