diff --git a/r2/r2/controllers/toolbar.py b/r2/r2/controllers/toolbar.py index 75195ed24..a994e8d64 100644 --- a/r2/r2/controllers/toolbar.py +++ b/r2/r2/controllers/toolbar.py @@ -203,10 +203,9 @@ class ToolbarController(RedditController): wrapper = make_wrapper(render_class = StarkComment, target = "_top") b = TopCommentBuilder(link, CommentSortMenu.operator('confidence'), - wrap = wrapper) + num=10, wrap=wrapper) - listing = NestedListing(b, num = 10, # TODO: add config var - parent_name = link._fullname) + listing = NestedListing(b, parent_name=link._fullname) raw_bar = strings.comments_panel_text % dict( fd_link=link.permalink) diff --git a/r2/r2/lib/pages/pages.py b/r2/r2/lib/pages/pages.py index 4461db68a..923aeac3a 100644 --- a/r2/r2/lib/pages/pages.py +++ b/r2/r2/lib/pages/pages.py @@ -1382,9 +1382,8 @@ class CommentPane(Templated): def renderer(): builder = CommentBuilder(article, sort, comment=comment, - context=context, **kw) - listing = NestedListing(builder, num = num, - parent_name = article._fullname) + context=context, num=num, **kw) + listing = NestedListing(builder, parent_name=article._fullname) return listing.listing() # disable the cache if the user is the author of anything in the diff --git a/r2/r2/lib/recommender.py b/r2/r2/lib/recommender.py index e48b5a225..0891356b0 100644 --- a/r2/r2/lib/recommender.py +++ b/r2/r2/lib/recommender.py @@ -229,10 +229,9 @@ def get_comment_items(srs, src, count=4): operators.desc('_confidence'), comment=None, context=None, + num=1, load_more=False) - listing = NestedListing(builder, - num=1, - parent_name=link._fullname).listing() + listing = NestedListing(builder, parent_name=link._fullname).listing() top_comments.extend(listing.things) srs = Subreddit._byID([com.sr_id for com in top_comments]) links = Link._byID([com.link_id for com in top_comments]) diff --git a/r2/r2/models/builder.py b/r2/r2/models/builder.py index 602f18468..d4e4a09cc 100755 --- a/r2/r2/models/builder.py +++ b/r2/r2/models/builder.py @@ -688,7 +688,7 @@ def make_wrapper(parent_wrapper = Wrapped, **params): class CommentBuilder(Builder): def __init__(self, link, sort, comment=None, children=None, context=None, load_more=True, continue_this_thread=True, - max_depth = MAX_RECURSION, **kw): + max_depth=MAX_RECURSION, num=None, **kw): Builder.__init__(self, **kw) self.link = link self.comment = comment @@ -696,6 +696,7 @@ class CommentBuilder(Builder): self.context = context or 0 self.load_more = load_more self.max_depth = max_depth + self.num = num # This is almost always True, except in the toolbar comments panel, # where we never want to see "continue this thread" links @@ -710,7 +711,7 @@ class CommentBuilder(Builder): sort_val = -sorter[comment] if self.rev_sort else sorter[comment] heapq.heappush(candidates, (sort_val, comment)) - def get_items(self, num): + def get_items(self): timer = g.stats.get_timer("CommentBuilder.get_items") timer.start() r = link_comments_and_sort(self.link, self.sort.col) @@ -772,7 +773,7 @@ class CommentBuilder(Builder): # choose which comments to show items = [] - while len(items) < num and candidates: + while (self.num is None or len(items) < self.num) and candidates: sort_val, comment_id = heapq.heappop(candidates) if comment_id not in cids: continue @@ -1072,14 +1073,14 @@ class MultiredditMessageBuilder(MessageBuilder): class TopCommentBuilder(CommentBuilder): """A comment builder to fetch only the top-level, non-spam, non-deleted comments""" - def __init__(self, link, sort, wrap = Wrapped): + def __init__(self, link, sort, num=None, wrap=Wrapped): CommentBuilder.__init__(self, link, sort, load_more = False, continue_this_thread = False, - max_depth = 1, wrap = wrap) + max_depth=1, wrap=wrap, num=num) - def get_items(self, num = 10): - final = CommentBuilder.get_items(self, num = num) + def get_items(self): + final = CommentBuilder.get_items(self) return [ cm for cm in final if not cm.deleted ] class SrMessageBuilder(MessageBuilder): diff --git a/r2/r2/models/listing.py b/r2/r2/models/listing.py index e9c2f2502..f47c6cac1 100644 --- a/r2/r2/models/listing.py +++ b/r2/r2/models/listing.py @@ -275,7 +275,7 @@ class NestedListing(Listing): ##TODO use the local builder with the render cache. this may ##require separating the builder's get_items and tree-building ##functionality - wrapped_items = self.get_items(num = self.num) + wrapped_items = self.get_items() self.things = wrapped_items