safemarkdown: Skip c.cname lookup when possible.

This commit is contained in:
Neil Williams
2011-11-18 16:29:24 -08:00
parent 3825d31a2f
commit 59fb2a9b89
4 changed files with 10 additions and 5 deletions

View File

@@ -194,7 +194,7 @@ def markdown_souptest(text, nofollow=False, target=None):
if not text:
return text
smd = safemarkdown(text, nofollow, target)
smd = safemarkdown(text, nofollow=nofollow, target=target)
# Prepend a DTD reference so we can load up definitions of all the standard
# XHTML entities ( , etc.).
@@ -210,11 +210,14 @@ def markdown_souptest(text, nofollow=False, target=None):
#TODO markdown should be looked up in batch?
#@memoize('markdown')
def safemarkdown(text, nofollow=False, target=None, wrap=True):
def safemarkdown(text, nofollow=False, wrap=True, **kwargs):
if not text:
return None
if c.cname and not target:
# this lets us skip the c.cname lookup (which is apparently quite
# slow) if target was explicitly passed to this function.
target = kwargs.get("target", None)
if "target" not in kwargs and c.cname:
target = "_top"
text = snudown.markdown(_force_utf8(text), nofollow, target)

View File

@@ -3015,6 +3015,7 @@ class SelfTextChild(LinkChild):
u = UserText(self.link, self.link.selftext,
editable = c.user == self.link.author,
nofollow = self.nofollow,
target="_top" if c.cname else None,
expunged=self.link.expunged)
return u.render()

View File

@@ -738,7 +738,7 @@ class Comment(Thing, Printable):
add_attr(item.attribs, 'S',
link = item.link.make_permalink(item.subreddit))
if not hasattr(item, 'target'):
item.target = None
item.target = "_top" if cname else None
if item.parent_id:
if item.parent_id in cids:
item.parent_permalink = '#' + utils.to36(item.parent_id)

View File

@@ -339,6 +339,7 @@ class Subreddit(Thing, Printable):
names = ('subscriber', 'moderator', 'contributor')
rels = (SRMember._fast_query(wrapped, [user], names) if c.user_is_loggedin else {})
defaults = Subreddit.default_subreddits()
target = "_top" if c.cname else None
for item in wrapped:
if not user or not user.has_subscribed:
item.subscriber = item._id in defaults
@@ -365,7 +366,7 @@ class Subreddit(Thing, Printable):
#will seem less horrible when add_props is in pages.py
from r2.lib.pages import UserText
item.usertext = UserText(item, item.description)
item.usertext = UserText(item, item.description, target=target)
Printable.add_props(user, wrapped)