Index: trunk/extensions/CodeReview/backend/CodeRepository.php |
— | — | @@ -257,7 +257,35 @@ |
258 | 258 | wfProfileOut( __METHOD__ ); |
259 | 259 | return $data; |
260 | 260 | } |
| 261 | + |
| 262 | + /** |
| 263 | + * Set diff cache (for import operations) |
| 264 | + * @param $codeRev CodeRevision |
| 265 | + */ |
| 266 | + public function setDiffCache( CodeRevision $codeRev ) { |
| 267 | + global $wgMemc; |
| 268 | + wfProfileIn( __METHOD__ ); |
261 | 269 | |
| 270 | + $rev1 = $codeRev->getId() - 1; |
| 271 | + $rev2 = $codeRev->getId(); |
| 272 | + |
| 273 | + $svn = SubversionAdaptor::newFromRepo( $this->mPath ); |
| 274 | + $data = $svn->getDiff( '', $rev1, $rev2 ); |
| 275 | + // Store to cache |
| 276 | + $key = wfMemcKey( 'svn', md5( $this->mPath ), 'diff', $rev1, $rev2 ); |
| 277 | + $wgMemc->set( $key, $data, 3600 * 24 * 3 ); |
| 278 | + // Permanent DB storage |
| 279 | + $storedData = $data; |
| 280 | + $flags = Revision::compressRevisionText( $storedData ); |
| 281 | + $dbw = wfGetDB( DB_MASTER ); |
| 282 | + $dbw->update( 'code_rev', |
| 283 | + array( 'cr_diff' => $storedData, 'cr_flags' => $flags ), |
| 284 | + array( 'cr_repo_id' => $this->mId, 'cr_id' => $codeRev->getId() ), |
| 285 | + __METHOD__ |
| 286 | + ); |
| 287 | + wfProfileOut( __METHOD__ ); |
| 288 | + } |
| 289 | + |
262 | 290 | /** |
263 | 291 | * Is the requested revid a valid revision to show? |
264 | 292 | * @return bool |
Index: trunk/extensions/CodeReview/api/ApiCodeUpdate.php |
— | — | @@ -41,6 +41,7 @@ |
42 | 42 | }
|
43 | 43 |
|
44 | 44 | $result = array();
|
| 45 | + $revs = array();
|
45 | 46 | foreach ( $log as $data ) {
|
46 | 47 | $codeRev = CodeRevision::newFromSvn( $repo, $data );
|
47 | 48 | $codeRev->save();
|
— | — | @@ -50,12 +51,13 @@ |
51 | 52 | 'timestamp' => wfTimestamp( TS_ISO_8601, $codeRev->getTimestamp() ),
|
52 | 53 | 'message' => $codeRev->getMessage()
|
53 | 54 | );
|
| 55 | + $revs[] = $codeRev;
|
54 | 56 | }
|
55 | 57 | // Cache the diffs if there are a only a few.
|
56 | 58 | // Mainly for WMF post-commit ping hook...
|
57 | | - if ( count( $result ) <= 2 ) {
|
58 | | - foreach ( $result as $revData ) {
|
59 | | - $diff = $repo->getDiff( $revData['id'] ); // trigger caching
|
| 59 | + if ( count( $revs ) <= 2 ) {
|
| 60 | + foreach ( $revs as $codeRev ) {
|
| 61 | + $repo->setDiffCache( $codeRev ); // trigger caching
|
60 | 62 | }
|
61 | 63 | }
|
62 | 64 | $this->getResult()->setIndexedTagName( $result, 'rev' );
|