Index: trunk/extensions/CodeReview/ui/CodeRevisionView.php |
— | — | @@ -366,7 +366,7 @@ |
367 | 367 | $cache = ''; |
368 | 368 | } |
369 | 369 | $diff = $this->mRepo->getDiff( $this->mRev->getId(), $cache ); |
370 | | - if ( (is_null($diff) || is_integer($diff)) && $deferDiffs ) { |
| 370 | + if ( is_integer($diff) && $deferDiffs ) { |
371 | 371 | // We'll try loading it by AJAX... |
372 | 372 | return $this->stubDiffLoader(); |
373 | 373 | } elseif ( strlen( $diff ) > $wgCodeReviewMaxDiffSize ) { |
Index: trunk/extensions/CodeReview/CodeReview.php |
— | — | @@ -119,6 +119,7 @@ |
120 | 120 | define("DIFFRESULT_NothingToCompare", 1); |
121 | 121 | define("DIFFRESULT_TooManyPaths", 2); |
122 | 122 | define("DIFFRESULT_NoDataReturned", 3); |
| 123 | +define("DIFFRESULT_NotInCache", 4); |
123 | 124 | |
124 | 125 | // If you can't directly access the remote SVN repo, you can set this |
125 | 126 | // to an offsite proxy running this fun little proxy tool: |
Index: trunk/extensions/CodeReview/backend/CodeRepository.php |
— | — | @@ -260,9 +260,6 @@ |
261 | 261 | * @param $useCache 'skipcache' to avoid caching |
262 | 262 | * 'cached' to *only* fetch if cached |
263 | 263 | * @return string|int The diff text on success, a DIFFRESULT_* constant on failure. |
264 | | - * @fixme Actually returns null if $useCache='cached' and there's no cached |
265 | | - * data. Either add a relevant constant or fix the comment above; |
266 | | - * caller in CodeRevisionView fixed by adding is_null check. |
267 | 264 | */ |
268 | 265 | public function getDiff( $rev, $useCache = '' ) { |
269 | 266 | global $wgMemc, $wgCodeReviewMaxDiffPaths; |
— | — | @@ -331,30 +328,38 @@ |
332 | 329 | |
333 | 330 | // If the data was not already in the cache or in the DB, we need to retrieve |
334 | 331 | // it from SVN. |
335 | | - if ( !$data && $useCache !== 'cached' ) { |
336 | | - $svn = SubversionAdaptor::newFromRepo( $this->path ); |
337 | | - $data = $svn->getDiff( '', $rev1, $rev2 ); |
| 332 | + if ( !$data ) { |
| 333 | + // If the calling code is forcing a cache check, report that it wasn't |
| 334 | + // in the cache. |
| 335 | + if ( $useCache === 'cached' ) { |
| 336 | + $data = DIFFRESULT_NotInCache; |
338 | 337 | |
339 | | - // If $data is blank, report the error that no data was returned. |
340 | | - // TODO: Currently we can't tell the difference between an SVN/connection |
341 | | - // failure and an empty diff. See if we can remedy this! |
342 | | - if ($data == "") { |
343 | | - $data = DIFFRESULT_NoDataReturned; |
| 338 | + // Otherwise, retrieve the diff using SubversionAdaptor. |
344 | 339 | } else { |
345 | | - // Otherwise, store the resulting diff to both the temporary cache and |
346 | | - // permanent DB storage. |
347 | | - // Store to cache |
348 | | - $wgMemc->set( $key, $data, 3600 * 24 * 3 ); |
| 340 | + $svn = SubversionAdaptor::newFromRepo( $this->path ); |
| 341 | + $data = $svn->getDiff( '', $rev1, $rev2 ); |
349 | 342 | |
350 | | - // Permanent DB storage |
351 | | - $storedData = $data; |
352 | | - $flags = Revision::compressRevisionText( $storedData ); |
353 | | - $dbw = wfGetDB( DB_MASTER ); |
354 | | - $dbw->update( 'code_rev', |
355 | | - array( 'cr_diff' => $storedData, 'cr_flags' => $flags ), |
356 | | - array( 'cr_repo_id' => $this->id, 'cr_id' => $rev ), |
357 | | - __METHOD__ |
358 | | - ); |
| 343 | + // If $data is blank, report the error that no data was returned. |
| 344 | + // TODO: Currently we can't tell the difference between an SVN/connection |
| 345 | + // failure and an empty diff. See if we can remedy this! |
| 346 | + if ($data == "") { |
| 347 | + $data = DIFFRESULT_NoDataReturned; |
| 348 | + } else { |
| 349 | + // Otherwise, store the resulting diff to both the temporary cache and |
| 350 | + // permanent DB storage. |
| 351 | + // Store to cache |
| 352 | + $wgMemc->set( $key, $data, 3600 * 24 * 3 ); |
| 353 | + |
| 354 | + // Permanent DB storage |
| 355 | + $storedData = $data; |
| 356 | + $flags = Revision::compressRevisionText( $storedData ); |
| 357 | + $dbw = wfGetDB( DB_MASTER ); |
| 358 | + $dbw->update( 'code_rev', |
| 359 | + array( 'cr_diff' => $storedData, 'cr_flags' => $flags ), |
| 360 | + array( 'cr_repo_id' => $this->id, 'cr_id' => $rev ), |
| 361 | + __METHOD__ |
| 362 | + ); |
| 363 | + } |
359 | 364 | } |
360 | 365 | } |
361 | 366 | |