* Renamed mDoneWrites to be clearer at what type it is.
* Also cleaned up a few callers of this method
Change-Id: I45856b210c289c2e2f193cc4328a208e20b4e0a8
public static function isWhitelistedFromAutoblocks( $ip ) {
// Try to get the autoblock_whitelist from the cache, as it's faster
// than getting the msg raw and explode()'ing it.
- $cache = ObjectCache::getMainWANInstance();
+ $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
$lines = $cache->getWithSetCallback(
wfMemcKey( 'ipb', 'autoblock', 'whitelist' ),
$cache::TTL_DAY,
- function () {
+ function ( $curValue, &$ttl, array &$setOpts ) {
+ $setOpts += Database::getCacheSetOptions( wfGetDB( DB_REPLICA ) );
+
return explode( "\n",
wfMessage( 'autoblock_whitelist' )->inContentLanguage()->plain() );
}
* @file
*/
use MediaWiki\Linker\LinkTarget;
+use MediaWiki\MediaWikiServices;
/**
* @todo document
* @since 1.28
*/
public static function newKnownCurrent( IDatabase $db, $pageId, $revId ) {
- $cache = ObjectCache::getMainWANInstance();
+ $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
return $cache->getWithSetCallback(
// Page/rev IDs passed in from DB to reflect history merges
$cache->makeGlobalKey( 'revision', $db->getWikiID(), $pageId, $revId ),
$dbr = wfGetDB( DB_REPLICA );
$dbrWatchlist = wfGetDB( DB_REPLICA, 'watchlist' );
-
$setOpts += Database::getCacheSetOptions( $dbr, $dbrWatchlist );
$watchedItemStore = MediaWikiServices::getInstance()->getWatchedItemStore();
$cValue = $this->get( $key, $curTTL, $checkKeys, $asOf ); // current value
$value = $cValue; // return value
- // Determine if a regeneration is desired
+ $preCallbackTime = microtime( true );
+ // Determine if a cached value regeneration is needed or desired
if ( $value !== false
&& $curTTL > 0
&& $this->isValid( $value, $versioned, $asOf, $minTime )
&& !$this->worthRefreshExpiring( $curTTL, $lowTTL )
- && !$this->worthRefreshPopular( $asOf, $ageNew, $popWindow )
+ && !$this->worthRefreshPopular( $asOf, $ageNew, $popWindow, $preCallbackTime )
) {
return $value;
}
}
if ( $value !== false && $ttl >= 0 ) {
- // Update the cache; this will fail if the key is tombstoned
$setOpts['lockTSE'] = $lockTSE;
+ // Use best known "since" timestamp if not provided
+ $setOpts += [ 'since' => $preCallbackTime ];
+ // Update the cache; this will fail if the key is tombstoned
$this->set( $key, $value, $ttl, $setOpts );
}
* @param float $asOf UNIX timestamp of the value
* @param integer $ageNew Age of key when this might recommend refreshing (seconds)
* @param integer $timeTillRefresh Age of key when it should be refreshed if popular (seconds)
+ * @param float $now The current UNIX timestamp
* @return bool
*/
- protected function worthRefreshPopular( $asOf, $ageNew, $timeTillRefresh ) {
- $age = microtime( true ) - $asOf;
+ protected function worthRefreshPopular( $asOf, $ageNew, $timeTillRefresh, $now ) {
+ $age = $now - $asOf;
$timeOld = $age - $ageNew;
if ( $timeOld <= 0 ) {
return false;
/** @var string SQL query */
protected $mLastQuery = '';
- /** @var bool */
- protected $mDoneWrites = false;
+ /** @var float|bool UNIX timestamp of last write query */
+ protected $mLastWriteTime = false;
/** @var string|bool */
protected $mPHPError = false;
/** @var string */
}
public function doneWrites() {
- return (bool)$this->mDoneWrites;
+ return (bool)$this->mLastWriteTime;
}
public function lastDoneWrites() {
- return $this->mDoneWrites ?: false;
+ return $this->mLastWriteTime ?: false;
}
public function writesPending() {
throw new DBReadOnlyError( $this, "Database is read-only: $reason" );
}
# Set a flag indicating that writes have been done
- $this->mDoneWrites = microtime( true );
+ $this->mLastWriteTime = microtime( true );
}
// Add trace comment to the begin of the sql string, right after the operator.
$writeTime = $this->pendingWriteQueryDuration( self::ESTIMATE_DB_APPLY );
$this->doCommit( $fname );
if ( $this->mTrxDoneWrites ) {
- $this->mDoneWrites = microtime( true );
+ $this->mLastWriteTime = microtime( true );
$this->trxProfiler->transactionWritingOut(
$this->mServer, $this->mDBname, $this->mTrxShortId, $writeTime );
}