From 602f1f6904cff9ca61c66303c1b58593905ff2cf Mon Sep 17 00:00:00 2001 From: ketralnis Date: Mon, 18 Oct 2010 14:38:59 -0700 Subject: [PATCH] Apply patch from Preston4tw (Preston Bennes ) to make /r/foo/comments work --- r2/r2/lib/db/queries.py | 26 ++++++++++++++++++-------- r2/r2/models/subreddit.py | 16 +++++++++++++++- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/r2/r2/lib/db/queries.py b/r2/r2/lib/db/queries.py index 87dca259df..d7fd795f30 100644 --- a/r2/r2/lib/db/queries.py +++ b/r2/r2/lib/db/queries.py @@ -417,6 +417,12 @@ def get_all_comments(): q = Comment._query(sort = desc('_date')) return make_results(q) +def get_sr_comments(sr): + """the subreddit /r/foo/comments page""" + q = Comment._query(Comment.c.sr_id == sr._id, + sort = desc('_date')) + return make_results(q) + def get_comments(user, sort, time): return user_query(Comment, user, sort, time) @@ -573,8 +579,8 @@ def new_comment(comment, inbox_rels): job.append(get_all_comments()) add_queries(job, delete_items = comment) else: + sr = Subreddit._byID(comment.sr_id) if comment._spam: - sr = Subreddit._byID(comment.sr_id) job.append(get_spam_comments(sr)) add_queries(job, insert_items = comment) amqp.add_item('new_comment', comment._fullname) @@ -751,7 +757,8 @@ def del_or_ban(things, why): if comments: add_queries([get_spam_comments(sr)], insert_items = comments) - add_queries([get_all_comments()], delete_items = comments) + add_queries([get_all_comments(), + get_sr_comments(sr)], delete_items = comments) changed(things) @@ -781,7 +788,8 @@ def unban(things): if comments: add_queries([get_spam_comments(sr)], delete_items = comments) - add_queries([get_all_comments()], insert_items = comments) + add_queries([get_all_comments(), + get_sr_comments(sr)], insert_items = comments) changed(things) @@ -802,12 +810,12 @@ def clear_reports(things): sr = srs[sr_id] links = [ x for x in sr_things if isinstance(x, Link) ] - #comments = [ x for x in sr_things if isinstance(x, Comment) ] + comments = [ x for x in sr_things if isinstance(x, Comment) ] if links: add_queries([get_reported_links(sr)], delete_items = links) - #if comments: - # add_queries([get_reported_comments(sr)], delete_items = comments) + if comments: + add_queries([get_reported_comments(sr)], delete_items = comments) def add_all_ban_report_srs(): """Adds the initial spam/reported pages to the report queue""" @@ -875,9 +883,11 @@ def run_new_comments(): def _run_new_comment(msg): fname = msg.body - comment = Comment._by_fullname(fname) + comment = Comment._by_fullname(fname,data=True) + sr = Subreddit._byID(comment.sr_id) - add_queries([get_all_comments()], + add_queries([get_all_comments(), + get_sr_comments(sr)], insert_items = [comment]) amqp.consume_items('newcomments_q', _run_new_comment) diff --git a/r2/r2/models/subreddit.py b/r2/r2/models/subreddit.py index 110c15be02..719500a191 100644 --- a/r2/r2/models/subreddit.py +++ b/r2/r2/models/subreddit.py @@ -313,7 +313,7 @@ def get_modqueue(self): def get_all_comments(self): from r2.lib.db import queries - return queries.get_all_comments() + return queries.get_sr_comments(self) @classmethod @@ -594,6 +594,10 @@ def can_change_stylesheet(self, user): def is_banned(self, user): return False + def get_all_comments(self): + from r2.lib.db import queries + return queries.get_all_comments() + class FriendsSR(FakeSubreddit): name = 'friends' title = 'friends' @@ -702,6 +706,10 @@ def get_links(self, sort, time): q._filter(queries.db_times[time]) return q + def get_all_comments(self): + from r2.lib.db import queries + return queries.get_all_comments() + def rising_srs(self): return None @@ -800,6 +808,12 @@ def get_links(self, sort, time): def rising_srs(self): return self.sr_ids + def get_all_comments(self): + from r2.lib.db.queries import get_sr_comments, merge_results + srs = Subreddit._byID(self.sr_ids, return_dict=False) + results = [get_sr_comments(sr) for sr in srs] + return merge_results(*results) + class RandomReddit(FakeSubreddit): name = 'random' header = ""