Merge lp:~mkanat/loggerhead/limit-pygments into lp:loggerhead

Proposed by Max Kanat-Alexander
Status: Merged
Approved by: Ian Clatworthy
Approved revision: 409
Merged at revision: not available
Proposed branch: lp:~mkanat/loggerhead/limit-pygments
Merge into: lp:loggerhead
Diff against target: 32 lines (+9/-0)
1 file modified
loggerhead/highlight.py (+9/-0)
To merge this branch: bzr merge lp:~mkanat/loggerhead/limit-pygments
Reviewer Review Type Date Requested Status
Ian Clatworthy (community) Approve
Review via email: mp+23900@code.launchpad.net

Commit message

Make pygments only highlight files if they're smaller than 512K, to prevent overloading loggerhead.

Description of the change

A fix for bug 513044--limit pygments to only being used on files 512K or smaller.

To post a comment you must log in.
lp:~mkanat/loggerhead/limit-pygments updated
409. By Max Kanat-Alexander

Don't put parens around the if condition

Revision history for this message
Ian Clatworthy (ian-clatworthy) wrote :

The value probably ought to be a configuration setting down the track but this looks a sensible improvement as is. If anything, I'd be tempted to make the default limit even lower, e.g. 256K.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'loggerhead/highlight.py'
--- loggerhead/highlight.py 2009-05-16 06:03:47 +0000
+++ loggerhead/highlight.py 2010-04-22 03:26:24 +0000
@@ -16,6 +16,8 @@
16# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA16# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17#17#
1818
19import cgi
20
19from pygments import highlight as _highlight_func21from pygments import highlight as _highlight_func
20from pygments.lexers import guess_lexer, guess_lexer_for_filename, TextLexer22from pygments.lexers import guess_lexer, guess_lexer_for_filename, TextLexer
21from pygments.formatters import HtmlFormatter23from pygments.formatters import HtmlFormatter
@@ -23,12 +25,19 @@
2325
24DEFAULT_PYGMENT_STYLE = 'colorful'26DEFAULT_PYGMENT_STYLE = 'colorful'
2527
28# Trying to highlight very large files using pygments was killing
29# loggerhead on launchpad.net, because pygments isn't very fast.
30# So we only highlight files if they're 512K or smaller.
31MAX_HIGHLIGHT_SIZE = 512000;
2632
27def highlight(path, text, encoding, style=DEFAULT_PYGMENT_STYLE):33def highlight(path, text, encoding, style=DEFAULT_PYGMENT_STYLE):
28 """34 """
29 Returns a list of highlighted (i.e. HTML formatted) strings.35 Returns a list of highlighted (i.e. HTML formatted) strings.
30 """36 """
3137
38 if len(text) > MAX_HIGHLIGHT_SIZE:
39 return map(cgi.escape, text.split('\n'))
40
32 formatter = HtmlFormatter(style=style, nowrap=True, classprefix='pyg-')41 formatter = HtmlFormatter(style=style, nowrap=True, classprefix='pyg-')
3342
34 try:43 try:

Subscribers

People subscribed via source and target branches