mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-25 14:58:27 -05:00
wiki: Cache wikified subreddit text on subreddit object.
This is a short-term solution until we figure out a better place to store this information. Currently, the property-getters are generating way too much traffic to Cassandra and we should continue using the old storage location for the latest revision.
This commit is contained in:
@@ -1462,8 +1462,10 @@ class ApiController(RedditController, OAuth2ResourceController):
|
||||
wikipage = wiki.WikiPage.create(sr, pagename)
|
||||
try:
|
||||
wr = wikipage.revise(value, previous=prev, author=c.user.name)
|
||||
setattr(sr, field, value)
|
||||
if not wr:
|
||||
return True
|
||||
setattr(sr, "prev_" + field + "_id", str(wikipage.revision))
|
||||
ModAction.create(c.site, c.user, 'wikirevise', details=wiki.modactions.get(pagename))
|
||||
return True
|
||||
except ConflictException as e:
|
||||
@@ -1558,6 +1560,24 @@ class ApiController(RedditController, OAuth2ResourceController):
|
||||
sr.sponsorship_url = sponsor_url or None
|
||||
sr.sponsorship_name = sponsor_name or None
|
||||
|
||||
if not apply_wikid_field(sr,
|
||||
form,
|
||||
'config/sidebar',
|
||||
description,
|
||||
prev_desc,
|
||||
'description',
|
||||
_("Sidebar was not saved")):
|
||||
return
|
||||
|
||||
if not apply_wikid_field(sr,
|
||||
form,
|
||||
'config/description',
|
||||
public_description,
|
||||
prev_pubdesc,
|
||||
'public_description',
|
||||
_("Description was not saved")):
|
||||
return
|
||||
|
||||
#assume sr existed, or was just built
|
||||
old_domain = sr.domain
|
||||
|
||||
@@ -1579,16 +1599,9 @@ class ApiController(RedditController, OAuth2ResourceController):
|
||||
changed(sr)
|
||||
form.parent().set_html('.status', _("saved"))
|
||||
|
||||
# don't go any further until the form validates
|
||||
if form.has_error():
|
||||
return
|
||||
|
||||
if not apply_wikid_field(sr, form, 'config/sidebar', description, prev_desc, 'description', _("Sidebar was not saved")):
|
||||
return
|
||||
if not apply_wikid_field(sr, form, 'config/description', public_description, prev_pubdesc, 'public_description', _("Description was not saved")):
|
||||
return
|
||||
|
||||
if redir:
|
||||
elif redir:
|
||||
form.redirect(redir)
|
||||
else:
|
||||
jquery.refresh()
|
||||
|
||||
@@ -67,6 +67,9 @@ import json
|
||||
page_descriptions = {'config/stylesheet':_("This page is the subreddit stylesheet, changes here apply to the subreddit css"),
|
||||
'config/sidebar':_("The contents of this page appear on the subreddit sidebar")}
|
||||
|
||||
ATTRIBUTE_BY_PAGE = {"config/sidebar": "description",
|
||||
"config/description": "public_description"}
|
||||
|
||||
class WikiController(RedditController):
|
||||
allow_stylesheets = True
|
||||
|
||||
@@ -247,6 +250,14 @@ class WikiApiController(WikiController):
|
||||
page.revise(content, previous, c.user.name, reason=request.POST['reason'])
|
||||
except ContentLengthError as e:
|
||||
self.handle_error(403, 'CONTENT_LENGTH_ERROR', max_length = e.max_length)
|
||||
|
||||
# continue storing the special pages as data attributes on the subreddit
|
||||
# object. TODO: change this to minimize subreddit get sizes.
|
||||
if page.special:
|
||||
setattr(c.site, ATTRIBUTE_BY_PAGE[page.name], content)
|
||||
setattr(c.site, "prev_" + ATTRIBUTE_BY_PAGE[page.name] + "_id", str(page.revision))
|
||||
c.site._commit()
|
||||
|
||||
if page.special or c.is_wiki_mod:
|
||||
description = modactions.get(page.name, 'Page %s edited' % page.name)
|
||||
ModAction.create(c.site, c.user, 'wikirevise', details=description)
|
||||
@@ -289,6 +300,13 @@ class WikiApiController(WikiController):
|
||||
else:
|
||||
try:
|
||||
page.revise(content, author=author, reason=reason, force=True)
|
||||
|
||||
# continue storing the special pages as data attributes on the subreddit
|
||||
# object. TODO: change this to minimize subreddit get sizes.
|
||||
if page.special:
|
||||
setattr(c.site, ATTRIBUTE_BY_PAGE[page.name], content)
|
||||
setattr(c.site, "prev_" + ATTRIBUTE_BY_PAGE[page.name] + "_id", page.revision)
|
||||
c.site._commit()
|
||||
except ContentLengthError as e:
|
||||
self.handle_error(403, 'CONTENT_LENGTH_ERROR', e.max_length)
|
||||
return json.dumps({})
|
||||
|
||||
@@ -89,6 +89,10 @@ class Subreddit(Thing, Printable):
|
||||
flair_self_assign_enabled = False,
|
||||
link_flair_self_assign_enabled = False,
|
||||
use_quotas = True,
|
||||
description = "",
|
||||
public_description = "",
|
||||
prev_description_id = "",
|
||||
prev_public_description_id = "",
|
||||
)
|
||||
_essentials = ('type', 'name', 'lang')
|
||||
_data_int_props = Thing._data_int_props + ('mod_actions', 'reported')
|
||||
@@ -206,49 +210,21 @@ class Subreddit(Thing, Printable):
|
||||
@property
|
||||
def moderators(self):
|
||||
return self.moderator_ids()
|
||||
|
||||
|
||||
@property
|
||||
def stylesheet_contents_user(self):
|
||||
try:
|
||||
return WikiPage.get(self, 'config/stylesheet')._get('content','')
|
||||
except tdb_cassandra.NotFound:
|
||||
return self._t.get('stylesheet_contents_user')
|
||||
|
||||
|
||||
@property
|
||||
def prev_stylesheet(self):
|
||||
try:
|
||||
return WikiPage.get(self, 'config/stylesheet')._get('revision','')
|
||||
except tdb_cassandra.NotFound:
|
||||
return ''
|
||||
|
||||
@property
|
||||
def description(self):
|
||||
try:
|
||||
return WikiPage.get(self, 'config/sidebar')._get('content','')
|
||||
except tdb_cassandra.NotFound:
|
||||
return self._t.get('description')
|
||||
|
||||
@property
|
||||
def public_description(self):
|
||||
try:
|
||||
return WikiPage.get(self, 'config/description')._get('content','')
|
||||
except tdb_cassandra.NotFound:
|
||||
return self._t.get('public_description')
|
||||
|
||||
@property
|
||||
def prev_description_id(self):
|
||||
try:
|
||||
return WikiPage.get(self, 'config/sidebar')._get('revision','')
|
||||
except tdb_cassandra.NotFound:
|
||||
return ''
|
||||
|
||||
@property
|
||||
def prev_public_description_id(self):
|
||||
try:
|
||||
return WikiPage.get(self, 'config/description')._get('revision','')
|
||||
except tdb_cassandra.NotFound:
|
||||
return ''
|
||||
|
||||
|
||||
@property
|
||||
def contributors(self):
|
||||
return self.contributor_ids()
|
||||
|
||||
Reference in New Issue
Block a user