r40940 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40939‎ | r40940 | r40941 >
Date:22:51, 16 September 2008
Author:aaron
Status:old
Tags:
Comment:
Performance tweaks:
* Bail out diffs if too many paths changed
* Pre-cache diffs with import script
Modified paths:
  • /trunk/extensions/CodeReview/CodeRepository.php (modified) (history)
  • /trunk/extensions/CodeReview/CodeRevision.php (modified) (history)
  • /trunk/extensions/CodeReview/CodeRevisionView.php (modified) (history)
  • /trunk/extensions/CodeReview/svnImport.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/CodeRevision.php
@@ -76,6 +76,14 @@
7777 __METHOD__
7878 );
7979 }
 80+
 81+ function isDiffable() {
 82+ $paths = $this->getModifiedPaths();
 83+ if( !$paths->numRows() || $paths->numRows() > 20 ) {
 84+ return false; // things need to get done this year
 85+ }
 86+ return true;
 87+ }
8088
8189 function saveComment( $text, $review, $parent=null ) {
8290 global $wgUser;
Index: trunk/extensions/CodeReview/svnImport.php
@@ -35,7 +35,7 @@
3636 # stops new revisions from being added. Try to avoid this
3737 # by trying less at a time from the last point.
3838 if( $chunkSize <= 1 ) {
39 - die(); // done!
 39+ break; // done!
4040 }
4141 $chunkSize = max( 1, floor($chunkSize/4) );
4242 } else {
@@ -56,3 +56,17 @@
5757 $revSpeed );
5858 }
5959 }
 60+
 61+echo "Pre-caching the latest 50 diffs...\n";
 62+$dbw = wfGetDB( DB_MASTER );
 63+$res = $dbw->select( 'code_rev', 'cr_id',
 64+ array( 'cr_repo_id' => $repo->getId() ),
 65+ __METHOD__,
 66+ array( 'ORDER BY' => 'cr_id DESC', 'LIMIT' => 50 )
 67+);
 68+while( $row = $dbw->fetchObject( $res ) ) {
 69+ $rev = $repo->getRevision( $row->cr_id );
 70+ $diff = $repo->getDiff( $row->cr_id ); // trigger caching
 71+ echo "Diff r{$row->cr_id} done\n";
 72+}
 73+echo "Done!\n";
Index: trunk/extensions/CodeReview/CodeRepository.php
@@ -106,6 +106,11 @@
107107
108108 $rev1 = $rev - 1;
109109 $rev2 = $rev;
 110+
 111+ $revision = $this->getRevision( $rev );
 112+ if( !$revision->isDiffable() ) {
 113+ return false;
 114+ }
110115
111116 $key = wfMemcKey( 'svn', md5( $this->mPath ), 'diff', $rev1, $rev2 );
112117 $data = $wgMemc->get( $key );
@@ -113,7 +118,7 @@
114119 if( !$data ) {
115120 $svn = SubversionAdaptor::newFromRepo( $this->mPath );
116121 $data = $svn->getDiff( '', $rev1, $rev2 );
117 - $wgMemc->add( $key, $data, 86400 );
 122+ $wgMemc->set( $key, $data, 3600*24*3 );
118123 }
119124
120125 return $data;
Index: trunk/extensions/CodeReview/CodeRevisionView.php
@@ -56,13 +56,15 @@
5757 }
5858 $html .= '</table>';
5959
 60+ $diffHtml = $this->formatDiff();
 61+ if( $diffHtml ) {
 62+ $html .=
 63+ "<h2>" . wfMsgHtml( 'code-rev-diff' ) . "</h2>" .
 64+ "<div class='mw-codereview-diff'>" .
 65+ $diffHtml .
 66+ "</div>";
 67+ }
6068 $html .=
61 - "<h2>" . wfMsgHtml( 'code-rev-diff' ) . "</h2>" .
62 - "<div class='mw-codereview-diff'>" .
63 - $this->formatDiff() .
64 - "</div>";
65 -
66 - $html .=
6769 '<h2>'. wfMsgHtml( 'code-comments' ) .'</h2>' .
6870 $this->formatComments();
6971
@@ -160,6 +162,9 @@
161163
162164 function formatDiff() {
163165 $diff = $this->mRepo->getDiff( $this->mRev->getId() );
 166+ if( !$diff ) {
 167+ return false;
 168+ }
164169 return "<pre>" . htmlspecialchars( $diff ) . "</pre>";
165170 }
166171

Status & tagging log