def add_comments(comments):
 from r2.models.builder import write_comment_orders
 link_ids = [comment.link_id for comment in tup(comments)]
 links_by_id = Link._byID(link_ids)
 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_by_id[link_id]
  timer = g.stats.get_timer('comment_tree.add.1')
  timer.start()
  write_comment_scores(link, link_comments)
  timer.intermediate('scores')
  CommentTree.add_comments(link, link_comments)
  timer.intermediate('update')
  write_comment_orders(link)
  timer.intermediate('write_order')
  timer.stop()

def add_comments ( comments ) : from r2 . models . builder import write_comment_orders link_ids = [ comment . link_id for comment in tup ( comments ) ] links_by_id = Link . _byID ( link_ids ) 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_by_id [ link_id ] timer = g . stats . get_timer ( 'comment_tree.add.1' ) timer . start ( ) write_comment_scores ( link , link_comments ) timer . intermediate ( 'scores' ) CommentTree . add_comments ( link , link_comments ) timer . intermediate ( 'update' ) write_comment_orders ( link ) timer . intermediate ( 'write_order' ) timer . stop ( )
add comments to the commenttree and update scores .