r54213 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54212‎ | r54213 | r54214 >
Date:15:20, 2 August 2009
Author:aaron
Status:ok
Tags:
Comment:
Fix problems with api diff cache:
*Before even committing to the DB, ApiCodeUpdate called getDiff(), but getDiff() checks
if the revision exists in a slave in order to cache anything. New function setDiffCache() made to get around this.
Modified paths:
  • /trunk/extensions/CodeReview/api/ApiCodeUpdate.php (modified) (history)
  • /trunk/extensions/CodeReview/backend/CodeRepository.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/backend/CodeRepository.php
@@ -257,7 +257,35 @@
258258 wfProfileOut( __METHOD__ );
259259 return $data;
260260 }
 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__ );
261269
 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+
262290 /**
263291 * Is the requested revid a valid revision to show?
264292 * @return bool
Index: trunk/extensions/CodeReview/api/ApiCodeUpdate.php
@@ -41,6 +41,7 @@
4242 }
4343
4444 $result = array();
 45+ $revs = array();
4546 foreach ( $log as $data ) {
4647 $codeRev = CodeRevision::newFromSvn( $repo, $data );
4748 $codeRev->save();
@@ -50,12 +51,13 @@
5152 'timestamp' => wfTimestamp( TS_ISO_8601, $codeRev->getTimestamp() ),
5253 'message' => $codeRev->getMessage()
5354 );
 55+ $revs[] = $codeRev;
5456 }
5557 // Cache the diffs if there are a only a few.
5658 // 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
6062 }
6163 }
6264 $this->getResult()->setIndexedTagName( $result, 'rev' );

Status & tagging log