Skip to content

Commit

Permalink
consume_comment_vote_queue: Don't update commenttree if not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
bsimpson63 committed Nov 14, 2016
1 parent 49e8655 commit 77eaf71
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions r2/r2/lib/voting.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,13 @@ def process_message(msgs, chan):
def consume_comment_vote_queue(qname="vote_comment_q"):
@g.stats.amqp_processor(qname)
def process_message(msg):
from r2.lib.comment_tree import write_comment_scores
from r2.lib.db.queries import (
add_queries,
add_to_commentstree_q,
get_comments,
)
from r2.models.builder import get_active_sort_orders_for_link

vote_data = json.loads(msg.body)
hook = hooks.get_hook('vote.validate_vote_data')
Expand Down Expand Up @@ -395,9 +397,18 @@ def process_message(msg):
# updates will be handled by new_comment. Also only update scores
# periodically once a comment has many votes.
if not vote.is_automatic_initial_vote and not skip_score_update:
# send this comment to commentstree_q where we will update
# CommentScoresByLink, CommentTree (noop), and CommentOrderer
add_to_commentstree_q(comment)
# check whether this link is using precomputed sorts, if it is
# we'll need to push an update to commentstree_q
link = Link._byID(comment.link_id)
if get_active_sort_orders_for_link(link):
# send this comment to commentstree_q where we will update
# CommentScoresByLink, CommentTree (noop), and CommentOrderer
add_to_commentstree_q(comment)
else:
# the link isn't using precomputed sorts, so just update the
# scores
write_comment_scores(link, [comment])
timer.intermediate("update_scores")

timer.stop()
timer.flush()
Expand Down

0 comments on commit 77eaf71

Please sign in to comment.