Skip to content

Commit c7d0f5b

Browse files
committed
voting: Don't update comment scores on automatic initial vote
Score updates are processed through commentstree_q. When a new comment is created an automatic initial vote (by the comment's author) is created. This results in two messages in commentstree_q: one from the vote and one from queries.new_comments. Don't create the message from the vote because it is redundant. This will let us reduce the volume of messages in commentstree_q which is currently very high.
1 parent 9544da4 commit c7d0f5b

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

r2/r2/lib/voting.py

+27-16
Original file line numberDiff line numberDiff line change
@@ -371,22 +371,33 @@ def process_message(msg):
371371
vote.commit()
372372
timer.intermediate("create_vote_object")
373373

374-
vote_valid = vote.is_automatic_initial_vote or vote.effects.affects_score
375-
comment_valid = not (comment._spam or comment._deleted)
376-
if vote_valid and comment_valid:
377-
author = Account._byID(comment.author_id)
378-
add_queries(
379-
queries=[get_comments(author, sort, 'all') for sort in SORTS],
380-
insert_items=comment,
381-
)
382-
timer.intermediate("author_queries")
383-
384-
# update the score periodically when a comment has many votes
385-
update_threshold = g.live_config['comment_vote_update_threshold']
386-
update_period = g.live_config['comment_vote_update_period']
387-
num_votes = comment.num_votes
388-
if num_votes <= update_threshold or num_votes % update_period == 0:
389-
add_to_commentstree_q(comment)
374+
vote_invalid = (not vote.effects.affects_score and
375+
not vote.is_automatic_initial_vote)
376+
comment_invalid = comment._spam or comment._deleted
377+
if vote_invalid or comment_invalid:
378+
timer.stop()
379+
timer.flush()
380+
return
381+
382+
author = Account._byID(comment.author_id)
383+
add_queries(
384+
queries=[get_comments(author, sort, 'all') for sort in SORTS],
385+
insert_items=comment,
386+
)
387+
timer.intermediate("author_queries")
388+
389+
update_threshold = g.live_config['comment_vote_update_threshold']
390+
update_period = g.live_config['comment_vote_update_period']
391+
skip_score_update = (comment.num_votes > update_threshold and
392+
comment.num_votes % update_period != 0)
393+
394+
# skip updating scores if this was the automatic initial vote. those
395+
# updates will be handled by new_comment. Also only update scores
396+
# periodically once a comment has many votes.
397+
if not vote.is_automatic_initial_vote and not skip_score_update:
398+
# send this comment to commentstree_q where we will update
399+
# CommentScoresByLink, CommentTree (noop), and CommentOrderer
400+
add_to_commentstree_q(comment)
390401

391402
timer.stop()
392403
timer.flush()

0 commit comments

Comments
 (0)