Skip to content

Commit

Permalink
move search to providers
Browse files Browse the repository at this point in the history
  • Loading branch information
grandpaslab authored and John Hannon committed Apr 1, 2015
1 parent c6ddc59 commit a0af591
Show file tree
Hide file tree
Showing 50 changed files with 744 additions and 595 deletions.
2 changes: 0 additions & 2 deletions install-reddit.sh
Expand Up @@ -156,7 +156,6 @@ python-stripe
python-tinycss2
python-unidecode
python-mock
python-yaml
python-flask
geoip-bin
Expand Down Expand Up @@ -742,7 +741,6 @@ set_consumer_count commentstree_q 1
set_consumer_count newcomments_q 1
set_consumer_count vote_link_q 1
set_consumer_count vote_comment_q 1
set_consumer_count automoderator_q 0

chown -R $REDDIT_USER:$REDDIT_GROUP $CONSUMER_CONFIG_ROOT/

Expand Down
28 changes: 4 additions & 24 deletions r2/example.ini
Expand Up @@ -21,6 +21,8 @@ websocket = YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXowMTIzNDU2Nzg5
cdn_ip_verification =
# secret for authenticating private media embeds
media_embed = YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXowMTIzNDU2Nzg5
# secret for authenticating comment embeds
comment_embed = YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXowMTIzNDU2Nzg5
# secret for authenticating controller#action name
action_name = YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXowMTIzNDU2Nzg5
# secret for email notification one-click unsubscribe links
Expand Down Expand Up @@ -383,11 +385,6 @@ wiki_max_page_separators = 3


############################################ SEARCH
#
# search type defaults to cloudsearch
# set to 'solr' to use a solr index
SEARCH_TYPE =
#
# endpoint for link search
CLOUDSEARCH_SEARCH_API =
# endpoint for link upload
Expand All @@ -396,22 +393,7 @@ CLOUDSEARCH_DOC_API =
CLOUDSEARCH_SUBREDDIT_SEARCH_API =
# endpoint for subreddit upload
CLOUDSEARCH_SUBREDDIT_DOC_API =
#
# endpoint for link search
SOLR_SEARCH_HOST = 127.0.0.1
# endpoint for link upload
SOLR_DOC_HOST = 127.0.0.1
# endpoint for subreddit search
SOLR_SUBREDDIT_SEARCH_HOST = 127.0.0.1
# endpoint for subreddit upload
SOLR_SUBREDDIT_DOC_HOST = 127.0.0.1
# solr port
SOLR_PORT = 8983
# solr core name (defaults to 'collection1' if empty)
SOLR_CORE =
# default batch size is 500
# limit is hard-coded to 1000
SOLR_MIN_BATCH =


############################################ MEMCACHE
num_mc_clients = 5
Expand Down Expand Up @@ -457,16 +439,14 @@ known_image_domains = i.imgur.com, giant.gfycat.com, pbs.twimg.com, upload.wikim
import_private = false
# location of geoip service
geoip_location = http://127.0.0.1:5000
# account name that AutoModerator actions will be done by
automoderator_account =


############################################ AUTHENTICATION
# how to authenticate users. options are:
# cookie: standard cookie-based auth
# http: http basic authentication
# or write your own!
authentication_provider = cookie
authentication_provider = http
# the work factor for bcrypt, increment this every time computers double in
# speed. don't worry, changing this won't break old passwords
bcrypt_work_factor = 12
Expand Down
8 changes: 0 additions & 8 deletions r2/r2/config/queues.py
Expand Up @@ -85,7 +85,6 @@ def declare_queues(g):
"butler_q": MessageQueue(),
"markread_q": MessageQueue(),
"del_account_q": MessageQueue(),
"automoderator_q": MessageQueue(),
})

if g.shard_link_vote_queues:
Expand All @@ -107,12 +106,5 @@ def declare_queues(g):
"usertext_edited")
queues.markread_q << "mark_all_read"
queues.del_account_q << "account_deleted"
queues.automoderator_q << (
"new_link",
"new_comment",
"new_media_embed",
"new_report",
"usertext_edited",
)

return queues
87 changes: 33 additions & 54 deletions r2/r2/controllers/api.py
Expand Up @@ -32,7 +32,7 @@
)

from pylons.i18n import _
from pylons import c, request, response
from pylons import g, c, request, response

from r2.lib.validator import *

Expand Down Expand Up @@ -81,7 +81,7 @@
from r2.lib.menus import CommentSortMenu
from r2.lib.captcha import get_iden
from r2.lib.strings import strings
from r2.lib.filters import _force_unicode, _force_utf8, websafe_json, websafe, spaceCompress
from r2.lib.filters import _force_unicode, websafe_json, websafe, spaceCompress
from r2.lib.template_helpers import format_html
from r2.lib.db import queries
from r2.lib import media
Expand All @@ -93,7 +93,7 @@
from r2.lib.filters import safemarkdown
from r2.lib.media import str_to_image
from r2.controllers.api_docs import api_doc, api_section
from r2.lib.search import SearchQuery
#from r2.lib.search import SearchQuery
from r2.controllers.oauth2 import require_oauth2_scope, allow_oauth2_access
from r2.lib.template_helpers import add_sr, get_domain, make_url_protocol_relative
from r2.lib.system_messages import notify_user_added
Expand Down Expand Up @@ -1134,19 +1134,13 @@ def POST_accept_moderator_invite(self, form, jquery):
notify_user_added("accept_moderator_invite", c.user, c.user, c.site)
jquery.refresh()

@validatedForm(
VUser(),
VModhash(),
VVerifyPassword("curpass", fatal=False),
# XXX: Is this necessary? Seems like it won't let people with
# passwords that would be invalid by current password rules clear
# their sessions.
password=VPasswordChange(
['curpass', 'curpass'],
docs=dict(curpass="the user's current password")
),
dest=VDestination(),
)
@validatedForm(VUser('curpass', default=''),
VModhash(),
password=VPasswordChange(
['curpass', 'curpass'],
docs=dict(curpass="the user's current password")
),
dest = VDestination())
def POST_clear_sessions(self, form, jquery, password, dest):
"""Clear all session cookies and replace the current one.
Expand All @@ -1171,16 +1165,13 @@ def POST_clear_sessions(self, form, jquery, password, dest):
# invalidated. drop a new cookie.
self.login(c.user)

@validatedForm(
VUser(),
VModhash(),
VVerifyPassword("curpass", fatal=False),
force_https=VBoolean("force_https"),
password=VPasswordChange(
["curpass", "curpass"],
docs=dict(curpass="the user's current password"),
),
)
@validatedForm(VUser("curpass", default=""),
VModhash(),
force_https=VBoolean("force_https"),
password=VPasswordChange(
["curpass", "curpass"],
docs=dict(curpass="the user's current password"),
))
def POST_set_force_https(self, form, jquery, password, force_https):
"""Toggle HTTPS-only sessions, invalidating other sessions.
Expand Down Expand Up @@ -1214,9 +1205,8 @@ def POST_set_force_https(self, form, jquery, password, force_https):
form.redirect(hsts_modify_redirect("/prefs/security"))

@validatedForm(
VUser(),
VUser('curpass', default=''),
VModhash(),
VVerifyPassword("curpass", fatal=False),
email=ValidEmails("email", num=1),
verify=VBoolean("verify"),
dest=VDestination(),
Expand Down Expand Up @@ -1265,9 +1255,8 @@ def POST_update_email(self, form, jquery, email, verify, dest):
form.set_text('.status', _('your email has been updated'))

@validatedForm(
VUser(),
VUser('curpass', default=''),
VModhash(),
VVerifyPassword("curpass", fatal=False),
password=VPasswordChange(['newpass', 'verpass']),
)
def POST_update_password(self, form, jquery, password):
Expand Down Expand Up @@ -1630,8 +1619,7 @@ def POST_block(self, thing):
return

block_acct = Account._byID(thing.author_id)
display_author = getattr(thing, "display_author", None)
if block_acct.name in g.admins or display_author:
if block_acct.name in g.admins or thing.display_author:
return
c.user.add_enemy(block_acct)

Expand Down Expand Up @@ -3961,15 +3949,12 @@ def GET_expando(self, link):
def POST_expando(self):
return self.GET_expando()

@validatedForm(
VUser(),
VModhash(),
VVerifyPassword("password", fatal=False),
VOneTimePassword("otp",
required=not g.disable_require_admin_otp),
remember=VBoolean("remember"),
dest=VDestination(),
)
@validatedForm(VUser('password', default=''),
VModhash(),
VOneTimePassword("otp",
required=not g.disable_require_admin_otp),
remember=VBoolean("remember"),
dest=VDestination())
def POST_adminon(self, form, jquery, remember, dest):
if c.user.name not in g.admins:
self.abort403()
Expand All @@ -3988,11 +3973,8 @@ def POST_adminon(self, form, jquery, remember, dest):
self.enable_admin_mode(c.user)
form.redirect(dest)

@validatedForm(
VUser(),
VModhash(),
VVerifyPassword("password", fatal=False),
)
@validatedForm(VUser("password", default=""),
VModhash())
def POST_generate_otp_secret(self, form, jquery):
if form.has_errors("password", errors.WRONG_PASSWORD):
return
Expand Down Expand Up @@ -4034,12 +4016,9 @@ def POST_enable_otp(self, form, jquery, otp):

form.redirect("/prefs/security")

@validatedForm(
VUser(),
VModhash(),
VVerifyPassword("password", fatal=False),
VOneTimePassword("otp", required=True),
)
@validatedForm(VUser("password", default=""),
VOneTimePassword("otp", required=True),
VModhash())
def POST_disable_otp(self, form, jquery):
if form.has_errors("password", errors.WRONG_PASSWORD):
return
Expand Down Expand Up @@ -4086,7 +4065,7 @@ def GET_subreddits_by_topic(self, responder, query):
exclude = Subreddit.default_subreddits()

faceting = {"reddit":{"sort":"-sum(text_relevance)", "count":20}}
results = SearchQuery(query, sort="relevance", faceting=faceting,
results = g.search_provider.SearchQuery(query, sort="relevance", faceting=faceting,
syntax="plain").run()

sr_results = []
Expand Down Expand Up @@ -4302,7 +4281,7 @@ def POST_modify_payment_blob(self, responder, code, signed, message):
updates = {}
updates["signed"] = signed
if message and message.strip() != "":
updates["giftmessage"] = _force_utf8(message)
updates["giftmessage"] = message

update_blob(str(code), updates)

Expand Down
26 changes: 6 additions & 20 deletions r2/r2/controllers/front.py
Expand Up @@ -255,13 +255,13 @@ def GET_comments(
# Determine if we should show the embed link for comments
c.can_embed = feature.is_enabled("comment_embeds") and bool(comment)

is_embed = embeds.prepare_embed_request(sr)
embed_key = embeds.prepare_embed_request(sr)

# check for 304
self.check_modified(article, 'comments')

if is_embed:
embeds.set_up_embed(sr, comment, showedits=showedits)
if embed_key:
embeds.set_up_embed(embed_key, sr, comment, showedits=showedits)

# Temporary hook until IAMA app "OP filter" is moved from partners
# Not to be open-sourced
Expand Down Expand Up @@ -380,16 +380,12 @@ def GET_comments(
suggested_sort = article.sort_if_suggested() if feature.is_enabled('default_sort') else None
if article.contest_mode:
if c.user_is_loggedin and sr.is_moderator(c.user):
# Default to top for contest mode to make determining winners
# easier, but allow them to override it for moderation
# purposes.
if 'sort' not in request.params:
sort = "top"
sort = "top"
else:
sort = "random"
elif suggested_sort and 'sort' not in request.params:
sort = suggested_sort
suggested_sort_active = True
sort = suggested_sort
suggested_sort_active = True

# finally add the comment listing
displayPane.append(CommentPane(article, CommentSortMenu.operator(sort),
Expand Down Expand Up @@ -572,16 +568,6 @@ def GET_moderationlog(self, num, after, reverse, count, mod, action):
mod = mods[mod_id]
mod_buttons.append(QueryButton(mod.name, mod.name,
query_param='mod'))
# add a choice for the automoderator account if it's not a mod
if (g.automoderator_account and
all(mod.name != g.automoderator_account
for mod in mods.values())):
automod_button = QueryButton(
g.automoderator_account,
g.automoderator_account,
query_param="mod",
)
mod_buttons.append(automod_button)
mod_buttons.append(QueryButton(_('admins*'), 'a', query_param='mod'))
base_path = request.path
menus = [NavMenu(action_buttons, base_path=base_path,
Expand Down
34 changes: 10 additions & 24 deletions r2/r2/controllers/listingcontroller.py
Expand Up @@ -457,32 +457,18 @@ def trending_info(cls):

def content(self):
content = super(HotController, self).content()

if c.render_style == "html":
stack = None
if isinstance(c.site, DefaultSR) and not self.listing_obj.prev:
trending_info = self.trending_info()
if trending_info:
stack = [
self.spotlight,
TrendingSubredditsBar(**trending_info),
self.listing_obj,
]
else:
hot_hook = hooks.get_hook("hot.get_content")
hot_pane = hot_hook.call_until_return(controller=self)
if hot_pane:
stack = [
self.spotlight,
hot_pane,
self.listing_obj
]

if stack:
return PaneStack(filter(None, stack), css_class='spacer')

if (c.render_style == "html" and isinstance(c.site, DefaultSR) and
not self.listing_obj.prev):
trending_info = self.trending_info()
if trending_info:
return PaneStack(filter(None, [
self.spotlight,
TrendingSubredditsBar(**trending_info),
self.listing_obj,
]), css_class='spacer')
return content


def title(self):
return c.site.title

Expand Down

0 comments on commit a0af591

Please sign in to comment.