mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-04-27 03:00:12 -04:00
CommentBuilder: take num as a constructor argument.
This follows the pattern of all other Builders.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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])
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user