Skip to content

Commit

Permalink
Randomize scores of all top level comments for shuffle sort
Browse files Browse the repository at this point in the history
This will ensure that all top level comments are considered for
display. It also makes it more clear that the sorting of child
comments is uneffected.
  • Loading branch information
bsimpson63 committed Feb 21, 2017
1 parent 33a8b4b commit 864681b
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions r2/r2/models/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
from r2.lib.jsontemplates import get_trimmed_sr_dicts
from r2.lib.utils import (
long_datetime,
shuffle_slice,
SimpleSillyStub,
Storage,
to36,
Expand Down Expand Up @@ -847,6 +846,15 @@ def get_comment_order(self):
self.link, sort_name, comment_tree.cids, comment_tree_timer)
comment_tree_timer.intermediate('get_scores')

if isinstance(self.sort, operators.shuffled):
# randomize the scores of top level comments
top_level_ids = comment_tree.tree.get(None, [])
top_level_scores = [
sorter[comment_id] for comment_id in top_level_ids]
shuffle(top_level_scores)
for i, comment_id in enumerate(top_level_ids):
sorter[comment_id] = top_level_scores[i]

self.timer.intermediate("load_storage")

comment_tree = self.modify_comment_tree(comment_tree)
Expand Down Expand Up @@ -1482,14 +1490,6 @@ def _make_wrapped_tree(self):

self.timer.intermediate("build_comments")

if isinstance(self.sort, operators.shuffled):
# If we have a sticky comment, do not shuffle the first element
# of the list.
if len(final) > 0 and final[0]._id == self.link.sticky_comment_id:
shuffle_slice(final, 1)
else:
shuffle(final)

if not self.load_more:
timer.stop()
return final
Expand Down

0 comments on commit 864681b

Please sign in to comment.