Skip to content

Commit

Permalink
safemarkdown: Skip c.cname lookup when possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
spladug committed Dec 1, 2011
1 parent 3825d31 commit 59fb2a9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
9 changes: 6 additions & 3 deletions r2/r2/lib/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.).
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions r2/r2/lib/pages/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -3015,6 +3015,7 @@ def content(self):
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()

Expand Down
2 changes: 1 addition & 1 deletion r2/r2/models/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ def add_props(cls, user, wrapped):
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)
Expand Down
3 changes: 2 additions & 1 deletion r2/r2/models/subreddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ def add_props(cls, user, wrapped):
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
Expand All @@ -365,7 +366,7 @@ def add_props(cls, user, wrapped):

#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)
Expand Down

0 comments on commit 59fb2a9

Please sign in to comment.