Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Apply patch from Preston4tw (Preston Bennes <preston.bennes@gmail.com>)
Browse files Browse the repository at this point in the history
to make /r/foo/comments work
  • Loading branch information
ketralnis committed Oct 18, 2010
1 parent 37e2ba9 commit 602f1f6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
26 changes: 18 additions & 8 deletions r2/r2/lib/db/queries.py
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand All @@ -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"""
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 15 additions & 1 deletion r2/r2/models/subreddit.py
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 = ""
Expand Down

0 comments on commit 602f1f6

Please sign in to comment.