Index: trunk/extensions/CodeReview/CodeRevision.php |
— | — | @@ -76,6 +76,14 @@ |
77 | 77 | __METHOD__ |
78 | 78 | ); |
79 | 79 | } |
| 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 | + } |
80 | 88 | |
81 | 89 | function saveComment( $text, $review, $parent=null ) { |
82 | 90 | global $wgUser; |
Index: trunk/extensions/CodeReview/svnImport.php |
— | — | @@ -35,7 +35,7 @@ |
36 | 36 | # stops new revisions from being added. Try to avoid this |
37 | 37 | # by trying less at a time from the last point. |
38 | 38 | if( $chunkSize <= 1 ) { |
39 | | - die(); // done! |
| 39 | + break; // done! |
40 | 40 | } |
41 | 41 | $chunkSize = max( 1, floor($chunkSize/4) ); |
42 | 42 | } else { |
— | — | @@ -56,3 +56,17 @@ |
57 | 57 | $revSpeed ); |
58 | 58 | } |
59 | 59 | } |
| 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 @@ |
107 | 107 | |
108 | 108 | $rev1 = $rev - 1; |
109 | 109 | $rev2 = $rev; |
| 110 | + |
| 111 | + $revision = $this->getRevision( $rev ); |
| 112 | + if( !$revision->isDiffable() ) { |
| 113 | + return false; |
| 114 | + } |
110 | 115 | |
111 | 116 | $key = wfMemcKey( 'svn', md5( $this->mPath ), 'diff', $rev1, $rev2 ); |
112 | 117 | $data = $wgMemc->get( $key ); |
— | — | @@ -113,7 +118,7 @@ |
114 | 119 | if( !$data ) { |
115 | 120 | $svn = SubversionAdaptor::newFromRepo( $this->mPath ); |
116 | 121 | $data = $svn->getDiff( '', $rev1, $rev2 ); |
117 | | - $wgMemc->add( $key, $data, 86400 ); |
| 122 | + $wgMemc->set( $key, $data, 3600*24*3 ); |
118 | 123 | } |
119 | 124 | |
120 | 125 | return $data; |
Index: trunk/extensions/CodeReview/CodeRevisionView.php |
— | — | @@ -56,13 +56,15 @@ |
57 | 57 | } |
58 | 58 | $html .= '</table>'; |
59 | 59 | |
| 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 | + } |
60 | 68 | $html .= |
61 | | - "<h2>" . wfMsgHtml( 'code-rev-diff' ) . "</h2>" . |
62 | | - "<div class='mw-codereview-diff'>" . |
63 | | - $this->formatDiff() . |
64 | | - "</div>"; |
65 | | - |
66 | | - $html .= |
67 | 69 | '<h2>'. wfMsgHtml( 'code-comments' ) .'</h2>' . |
68 | 70 | $this->formatComments(); |
69 | 71 | |
— | — | @@ -160,6 +162,9 @@ |
161 | 163 | |
162 | 164 | function formatDiff() { |
163 | 165 | $diff = $this->mRepo->getDiff( $this->mRev->getId() ); |
| 166 | + if( !$diff ) { |
| 167 | + return false; |
| 168 | + } |
164 | 169 | return "<pre>" . htmlspecialchars( $diff ) . "</pre>"; |
165 | 170 | } |
166 | 171 | |