r60646 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60645‎ | r60646 | r60647 >
Date:07:21, 5 January 2010
Author:tstarling
Status:ok
Tags:
Comment:
Don't attempt to format diffs more than 500KB in size. Fix for OOM observed in some very large diffs. Committing for test on server.
Modified paths:
  • /trunk/extensions/CodeReview/CodeReview.i18n.php (modified) (history)
  • /trunk/extensions/CodeReview/CodeReview.php (modified) (history)
  • /trunk/extensions/CodeReview/api/ApiCodeDiff.php (modified) (history)
  • /trunk/extensions/CodeReview/ui/CodeRevisionView.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/CodeReview.i18n.php
@@ -75,6 +75,7 @@
7676 'code-rev-inline-preview' => 'Preview:',
7777 'code-rev-diff' => 'Diff',
7878 'code-rev-diff-link' => 'diff',
 79+ 'code-rev-diff-too-large' => 'The diff is too large to display.',
7980 'code-rev-purge-link' => 'purge',
8081 'code-status-new' => 'new',
8182 'code-status-fixme' => 'fixme',
Index: trunk/extensions/CodeReview/CodeReview.php
@@ -140,6 +140,11 @@
141141 // Should match test runner's $wgParserTestRemote['secret'].
142142 $wgCodeReviewSharedSecret = false;
143143
 144+/**
 145+ * Maximum size of diff text before it is omitted from the revision view
 146+ */
 147+$wgCodeReviewMaxDiffSize = 500000;
 148+
144149 # Schema changes
145150 $wgHooks['LoadExtensionSchemaUpdates'][] = 'efCodeReviewSchemaUpdates';
146151
Index: trunk/extensions/CodeReview/api/ApiCodeDiff.php
@@ -3,7 +3,7 @@
44 class ApiCodeDiff extends ApiBase {
55
66 public function execute() {
7 - global $wgUser;
 7+ global $wgUser, $wgCodeReviewMaxDiffSize;
88 // Before doing anything at all, let's check permissions
99 if( !$wgUser->isAllowed('codereview-use') ) {
1010 $this->dieUsage('You don\'t have permission to view code diffs','permissiondenied');
@@ -31,12 +31,14 @@
3232
3333 $diff = $repo->getDiff( $params['rev'] );
3434
35 - if ( $diff ) {
 35+ if ( strval( $diff ) === '' ) {
 36+ // FIXME: Are we sure we don't want to throw an error here?
 37+ $html = 'Failed to load diff.';
 38+ } elseif ( strlen( $diff ) > $wgCodeReviewMaxDiffSize ) {
 39+ $html = 'Diff too large.';
 40+ } else {
3641 $hilite = new CodeDiffHighlighter();
3742 $html = $hilite->render( $diff );
38 - } else {
39 - // FIXME: Are we sure we don't want to throw an error here?
40 - $html = 'Failed to load diff.';
4143 }
4244
4345 $data = array(
Index: trunk/extensions/CodeReview/ui/CodeRevisionView.php
@@ -357,7 +357,7 @@
358358 }
359359
360360 protected function formatDiff() {
361 - global $wgEnableAPI;
 361+ global $wgEnableAPI, $wgCodeReviewMaxDiffSize;
362362
363363 // Asynchronous diff loads will require the API
364364 // And JS in the client, but tough shit eh? ;)
@@ -380,6 +380,8 @@
381381 if ( !$diff && $deferDiffs ) {
382382 // We'll try loading it by AJAX...
383383 return $this->stubDiffLoader();
 384+ } elseif ( strlen( $diff ) > $wgCodeReviewMaxDiffSize ) {
 385+ return htmlspecialchars( wfMsg( 'code-rev-diff-too-large' ) );
384386 } else {
385387 $hilite = new CodeDiffHighlighter();
386388 return $hilite->render( $diff );

Follow-up revisions

RevisionCommit summaryAuthorDate
r60647Merged r60646 from trunk.tstarling07:23, 5 January 2010

Status & tagging log