mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-26 07:19:25 -05:00
Convert /comments to new query cache.
This commit is contained in:
@@ -9,7 +9,7 @@ from r2.lib.solrsearch import DomainSearchQuery
|
||||
from r2.lib import amqp, sup, filters
|
||||
from r2.lib.comment_tree import add_comments, update_comment_votes
|
||||
from r2.models.query_cache import cached_query, merged_cached_query, UserQueryCache, CachedQueryMutator
|
||||
from r2.models.query_cache import ThingTupleComparator
|
||||
from r2.models.query_cache import ThingTupleComparator, SubredditQueryCache
|
||||
|
||||
import cPickle as pickle
|
||||
|
||||
@@ -436,10 +436,10 @@ def user_query(kind, user_id, sort, time):
|
||||
q._filter(db_times[time])
|
||||
return make_results(q)
|
||||
|
||||
@cached_query(SubredditQueryCache)
|
||||
def get_all_comments():
|
||||
"""the master /comments page"""
|
||||
q = Comment._query(sort = desc('_date'))
|
||||
return make_results(q)
|
||||
return Comment._query(sort=desc('_date'))
|
||||
|
||||
def get_sr_comments(sr):
|
||||
return _get_sr_comments(sr._id)
|
||||
@@ -616,7 +616,9 @@ def new_comment(comment, inbox_rels):
|
||||
if comment._deleted:
|
||||
job_key = "delete_items"
|
||||
job.append(get_sr_comments(sr))
|
||||
job.append(get_all_comments())
|
||||
|
||||
with CachedQueryMutator() as m:
|
||||
m.delete(get_all_comments(), [comment])
|
||||
else:
|
||||
job_key = "insert_items"
|
||||
if comment._spam:
|
||||
@@ -810,6 +812,7 @@ def del_or_ban(things, why):
|
||||
if not by_srid:
|
||||
return
|
||||
|
||||
comments_to_remove = []
|
||||
for sr_id, things in by_srid.iteritems():
|
||||
sr = srs[sr_id]
|
||||
links = [x for x in things if isinstance(x, Link)]
|
||||
@@ -831,11 +834,13 @@ def del_or_ban(things, why):
|
||||
|
||||
if comments:
|
||||
add_queries([get_spam_comments(sr)], insert_items = comments)
|
||||
add_queries([get_all_comments(),
|
||||
get_sr_comments(sr)], delete_items = comments)
|
||||
add_queries([get_sr_comments(sr)], delete_items = comments)
|
||||
comments_to_remove.extend(comments)
|
||||
|
||||
if why == "del":
|
||||
with CachedQueryMutator() as m:
|
||||
with CachedQueryMutator() as m:
|
||||
m.delete(get_all_comments(), comments_to_remove)
|
||||
|
||||
if why == "del":
|
||||
for author_id, things in _by_author(things).iteritems():
|
||||
links = [x for x in things if isinstance(x, Link)]
|
||||
if links:
|
||||
@@ -852,6 +857,7 @@ def unban(things):
|
||||
if not by_srid:
|
||||
return
|
||||
|
||||
all_comments = []
|
||||
for sr_id, things in by_srid.iteritems():
|
||||
sr = srs[sr_id]
|
||||
links = [x for x in things if isinstance(x, Link)]
|
||||
@@ -872,9 +878,12 @@ def unban(things):
|
||||
add_queries(results, insert_items = links)
|
||||
|
||||
if comments:
|
||||
all_comments.extend(comments)
|
||||
add_queries([get_spam_comments(sr)], delete_items = comments)
|
||||
add_queries([get_all_comments(),
|
||||
get_sr_comments(sr)], insert_items = comments)
|
||||
add_queries([get_sr_comments(sr)], insert_items = comments)
|
||||
|
||||
with CachedQueryMutator() as m:
|
||||
m.insert(get_all_comments(), all_comments)
|
||||
|
||||
changed(things)
|
||||
|
||||
@@ -971,8 +980,9 @@ def run_new_comments(limit=1000):
|
||||
fnames = [msg.body for msg in msgs]
|
||||
|
||||
comments = Comment._by_fullname(fnames, data=True, return_dict=False)
|
||||
add_queries([get_all_comments()],
|
||||
insert_items=comments)
|
||||
|
||||
with CachedQueryMutator() as m:
|
||||
m.insert(get_all_comments(), comments)
|
||||
|
||||
bysrid = _by_srid(comments, False)
|
||||
for srid, sr_comments in bysrid.iteritems():
|
||||
|
||||
Reference in New Issue
Block a user