From: Aaron Schulz Date: Tue, 6 Oct 2015 05:06:46 +0000 (-0700) Subject: Change getCacheSetOptions() callers to use "Database" X-Git-Tag: 1.31.0-rc.0~9523^2 X-Git-Url: http://git.cyclocoop.org/%22%2C%20generer_url_ecrire%28?a=commitdiff_plain;h=54758dd1606358cf47b36083e16573ad2f514091;p=lhc%2Fweb%2Fwiklou.git Change getCacheSetOptions() callers to use "Database" * This is less verbose that DatabaseBase * Also add a few WAN cache doc comments Change-Id: I5b6de6d0ffa06753ea96c50b63db7dae796475dc --- diff --git a/includes/User.php b/includes/User.php index 20b75bf095..75649a7881 100644 --- a/includes/User.php +++ b/includes/User.php @@ -458,7 +458,7 @@ class User implements IDBAccessObject { $data['mVersion'] = self::VERSION; $key = wfMemcKey( 'user', 'id', $this->mId ); - $opts = DatabaseBase::getCacheSetOptions( wfGetDB( DB_SLAVE ) ); + $opts = Database::getCacheSetOptions( wfGetDB( DB_SLAVE ) ); ObjectCache::getMainWANInstance()->set( $key, $data, 3600, $opts ); } diff --git a/includes/actions/InfoAction.php b/includes/actions/InfoAction.php index 4e74ed32e9..78dd5fe926 100644 --- a/includes/actions/InfoAction.php +++ b/includes/actions/InfoAction.php @@ -682,7 +682,7 @@ class InfoAction extends FormlessAction { $dbr = wfGetDB( DB_SLAVE ); $dbrWatchlist = wfGetDB( DB_SLAVE, 'watchlist' ); - $setOpts += DatabaseBase::getCacheSetOptions( $dbr, $dbrWatchlist ); + $setOpts += Database::getCacheSetOptions( $dbr, $dbrWatchlist ); $result = array(); diff --git a/includes/changetags/ChangeTags.php b/includes/changetags/ChangeTags.php index e1b9b27a4b..5531245679 100644 --- a/includes/changetags/ChangeTags.php +++ b/includes/changetags/ChangeTags.php @@ -1091,7 +1091,7 @@ class ChangeTags { return ObjectCache::getMainWANInstance()->getWithSetCallback( wfMemcKey( 'active-tags' ), function ( $oldValue, &$ttl, array &$setOpts ) { - $setOpts += DatabaseBase::getCacheSetOptions( wfGetDB( DB_SLAVE ) ); + $setOpts += Database::getCacheSetOptions( wfGetDB( DB_SLAVE ) ); // Ask extensions which tags they consider active $extensionActive = array(); @@ -1135,7 +1135,7 @@ class ChangeTags { function ( $oldValue, &$ttl, array &$setOpts ) use ( $fname ) { $dbr = wfGetDB( DB_SLAVE ); - $setOpts += DatabaseBase::getCacheSetOptions( $dbr ); + $setOpts += Database::getCacheSetOptions( $dbr ); $tags = $dbr->selectFieldValues( 'valid_tag', 'vt_tag', array(), $fname ); @@ -1160,7 +1160,7 @@ class ChangeTags { return ObjectCache::getMainWANInstance()->getWithSetCallback( wfMemcKey( 'valid-tags-hook' ), function ( $oldValue, &$ttl, array &$setOpts ) { - $setOpts += DatabaseBase::getCacheSetOptions( wfGetDB( DB_SLAVE ) ); + $setOpts += Database::getCacheSetOptions( wfGetDB( DB_SLAVE ) ); $tags = array(); Hooks::run( 'ListDefinedTags', array( &$tags ) ); @@ -1221,7 +1221,7 @@ class ChangeTags { function ( $oldValue, &$ttl, array &$setOpts ) use ( $fname ) { $dbr = wfGetDB( DB_SLAVE, 'vslow' ); - $setOpts += DatabaseBase::getCacheSetOptions( $dbr ); + $setOpts += Database::getCacheSetOptions( $dbr ); $res = $dbr->select( 'change_tag', diff --git a/includes/filerepo/LocalRepo.php b/includes/filerepo/LocalRepo.php index 389f081c19..02d859f28c 100644 --- a/includes/filerepo/LocalRepo.php +++ b/includes/filerepo/LocalRepo.php @@ -205,7 +205,7 @@ class LocalRepo extends FileRepo { function ( $oldValue, &$ttl, array &$setOpts ) use ( $that, $title ) { $dbr = $that->getSlaveDB(); // possibly remote DB - $setOpts += DatabaseBase::getCacheSetOptions( $dbr ); + $setOpts += Database::getCacheSetOptions( $dbr ); if ( $title instanceof Title ) { $row = $dbr->selectRow( diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index d5179cbc50..50b9cafeda 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -309,7 +309,7 @@ class LocalFile extends File { // Cache presence for 1 week and negatives for 1 day $ttl = $this->fileExists ? 86400 * 7 : 86400; - $opts = DatabaseBase::getCacheSetOptions( $this->repo->getSlaveDB() ); + $opts = Database::getCacheSetOptions( $this->repo->getSlaveDB() ); ObjectCache::getMainWANInstance()->set( $key, $cacheVal, $ttl, $opts ); } diff --git a/includes/interwiki/Interwiki.php b/includes/interwiki/Interwiki.php index 89aeaae68a..7a49f9be89 100644 --- a/includes/interwiki/Interwiki.php +++ b/includes/interwiki/Interwiki.php @@ -221,7 +221,7 @@ class Interwiki { function ( $oldValue, &$ttl, array &$setOpts ) use ( $prefix ) { $dbr = wfGetDB( DB_SLAVE ); - $setOpts += DatabaseBase::getCacheSetOptions( $dbr ); + $setOpts += Database::getCacheSetOptions( $dbr ); $row = $dbr->selectRow( 'interwiki', diff --git a/includes/libs/objectcache/WANObjectCache.php b/includes/libs/objectcache/WANObjectCache.php index b1d3ec2d60..7e70e4bb5e 100644 --- a/includes/libs/objectcache/WANObjectCache.php +++ b/includes/libs/objectcache/WANObjectCache.php @@ -269,10 +269,12 @@ class WANObjectCache { * - d) T1 reads the row and calls set() due to a cache miss * - e) Stale value is stuck in cache * + * Setting 'lag' helps avoids keys getting stuck in long-term stale states. + * * Example usage: * @code * $dbr = wfGetDB( DB_SLAVE ); - * $setOpts = DatabaseBase::getCacheSetOptions( $dbr ); + * $setOpts = Database::getCacheSetOptions( $dbr ); * // Fetch the row from the DB * $row = $dbr->selectRow( ... ); * $key = wfMemcKey( 'building', $buildingId ); @@ -505,6 +507,7 @@ class WANObjectCache { * can be set dynamically by altering $ttl in the callback (by reference). * The $setOpts array can be altered and is given to set() when called; * it is recommended to set the 'since' field to avoid race conditions. + * Setting 'lag' helps avoids keys getting stuck in long-term stale states. * * Usually, callbacks ignore the current value, but it can be used * to maintain "most recent X" values that come from time or sequence @@ -529,7 +532,7 @@ class WANObjectCache { * function ( $oldValue, &$ttl, array &$setOpts ) { * $dbr = wfGetDB( DB_SLAVE ); * // Account for any snapshot/slave lag - * $setOpts += DatabaseBase::getCacheSetOptions( $dbr ); + * $setOpts += Database::getCacheSetOptions( $dbr ); * * return $dbr->selectRow( ... ); * }, @@ -547,7 +550,7 @@ class WANObjectCache { * function ( $oldValue, &$ttl, array &$setOpts ) { * $dbr = wfGetDB( DB_SLAVE ); * // Account for any snapshot/slave lag - * $setOpts += DatabaseBase::getCacheSetOptions( $dbr ); + * $setOpts += Database::getCacheSetOptions( $dbr ); * * return CatConfig::newFromRow( $dbr->selectRow( ... ) ); * }, @@ -570,7 +573,7 @@ class WANObjectCache { * // Determine new value from the DB * $dbr = wfGetDB( DB_SLAVE ); * // Account for any snapshot/slave lag - * $setOpts += DatabaseBase::getCacheSetOptions( $dbr ); + * $setOpts += Database::getCacheSetOptions( $dbr ); * * return CatState::newFromResults( $dbr->select( ... ) ); * }, @@ -595,7 +598,7 @@ class WANObjectCache { * function ( $oldValue, &$ttl, array &$setOpts ) { * $dbr = wfGetDB( DB_SLAVE ); * // Account for any snapshot/slave lag - * $setOpts += DatabaseBase::getCacheSetOptions( $dbr ); + * $setOpts += Database::getCacheSetOptions( $dbr ); * * // Start off with the last cached list * $list = $oldValue ?: array();