mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-04-27 03:00:12 -04:00
Move subreddit name search to its own CF.
Subreddit name search is used for recommending subreddits to users as they type a name on the submission page. Also adds a missing script that is needed to load up the subreddit names into cassandra. This script should be run occasionally (we do it once per day) to fill/update the search cache.
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
from r2.models import *
|
||||
from r2.models import Subreddit
|
||||
from r2.lib.memoize import memoize
|
||||
from r2.lib.db.operators import desc
|
||||
from r2.lib import utils
|
||||
from r2.lib.db import tdb_cassandra
|
||||
from r2.lib.cache import CL_ONE
|
||||
|
||||
from pylons import g
|
||||
|
||||
sr_prefix = 'sr_search_'
|
||||
|
||||
class SubredditsByPartialName(tdb_cassandra.View):
|
||||
_use_db = True
|
||||
_value_type = 'pickle'
|
||||
_use_new_ring = True
|
||||
_read_consistency_level = CL_ONE
|
||||
|
||||
def load_all_reddits():
|
||||
query_cache = {}
|
||||
@@ -21,11 +26,17 @@ def load_all_reddits():
|
||||
if len(names) < 10:
|
||||
names.append(sr.name)
|
||||
|
||||
g.permacache.set_multi(query_cache, prefix = sr_prefix)
|
||||
for name_prefix, subreddits in query_cache.iteritems():
|
||||
SubredditsByPartialName._set_values(name_prefix, {'srs': subreddits})
|
||||
|
||||
def search_reddits(query):
|
||||
query = str(query.lower())
|
||||
return g.permacache.get(sr_prefix + query) or []
|
||||
|
||||
try:
|
||||
result = SubredditsByPartialName._byID(query)
|
||||
return result.srs
|
||||
except tdb_cassandra.NotFound:
|
||||
return []
|
||||
|
||||
@memoize('popular_searches', time = 3600)
|
||||
def popular_searches():
|
||||
|
||||
4
scripts/update_sr_names.sh
Executable file
4
scripts/update_sr_names.sh
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
cd ~/reddit/r2
|
||||
~/reddit/scripts/saferun.sh /tmp/update_sr_names.pid nice /usr/local/bin/paster --plugin=r2 run run.ini r2/lib/subreddit_search.py -c "load_all_reddits()"
|
||||
Reference in New Issue
Block a user