From: Aaron Schulz Date: Wed, 30 Sep 2015 06:40:25 +0000 (-0700) Subject: Converted Interwiki::load to using getWithSetCallback() X-Git-Tag: 1.31.0-rc.0~9642^2 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dcompta/operations/modifier.php?a=commitdiff_plain;h=7cb83f0bb34603ead0218e660f3268d8d9df6619;p=lhc%2Fweb%2Fwiklou.git Converted Interwiki::load to using getWithSetCallback() Change-Id: I4299715ce4c996fed8add773aa03441324eb0dfc --- diff --git a/includes/interwiki/Interwiki.php b/includes/interwiki/Interwiki.php index 33e506686e..2bfe756e78 100644 --- a/includes/interwiki/Interwiki.php +++ b/includes/interwiki/Interwiki.php @@ -209,49 +209,35 @@ class Interwiki { return Interwiki::loadFromArray( $iwData ); } - $cache = ObjectCache::getMainWANInstance(); - - if ( !$iwData ) { - $key = wfMemcKey( 'interwiki', $prefix ); - $iwData = $cache->get( $key ); - if ( $iwData === '!NONEXISTENT' ) { - // negative cache hit - return false; - } - } - - // is_array is hack for old keys - if ( $iwData && is_array( $iwData ) ) { + if ( is_array( $iwData ) ) { $iw = Interwiki::loadFromArray( $iwData ); if ( $iw ) { - return $iw; + return $iw; // handled by hook } } - $db = wfGetDB( DB_SLAVE ); + $iwData = ObjectCache::getMainWANInstance()->getWithSetCallback( + wfMemcKey( 'interwiki', $prefix ), + function ( $oldValue, &$ttl, array &$setOpts ) use ( $prefix ) { + $dbr = wfGetDB( DB_SLAVE ); - $row = $db->fetchRow( $db->select( - 'interwiki', - self::selectFields(), - array( 'iw_prefix' => $prefix ), - __METHOD__ - ) ); - - $iw = Interwiki::loadFromArray( $row ); - if ( $iw ) { - $mc = array( - 'iw_url' => $iw->mURL, - 'iw_api' => $iw->mAPI, - 'iw_local' => $iw->mLocal, - 'iw_trans' => $iw->mTrans - ); - $cache->set( $key, $mc, $wgInterwikiExpiry ); + $row = $dbr->selectRow( + 'interwiki', + Interwiki::selectFields(), + array( 'iw_prefix' => $prefix ), + __METHOD__ + ); - return $iw; - } + $setOpts = array( 'since' => $dbr->trxTimestamp() ); - // negative cache hit - $cache->set( $key, '!NONEXISTENT', $wgInterwikiExpiry ); + return $row ? (array)$row : '!NONEXISTENT'; + }, + $wgInterwikiExpiry + ); + + if ( is_array( $iwData ) ) { + return Interwiki::loadFromArray( $iwData ) ?: false; + } return false; }