jenkins-bot has submitted this change and it was merged.

Change subject: objectcache: use a default "since" timestamp in 
getWithSetCallback()
......................................................................


objectcache: use a default "since" timestamp in getWithSetCallback()

* Renamed mDoneWrites to be clearer at what type it is.
* Also cleaned up a few callers of this method

Change-Id: I45856b210c289c2e2f193cc4328a208e20b4e0a8
---
M includes/Block.php
M includes/Revision.php
M includes/actions/InfoAction.php
M includes/libs/objectcache/WANObjectCache.php
M includes/libs/rdbms/database/Database.php
5 files changed, 21 insertions(+), 15 deletions(-)

Approvals:
  Krinkle: Verified
  Ori.livneh: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/Block.php b/includes/Block.php
index 098d51c..a11ba26 100644
--- a/includes/Block.php
+++ b/includes/Block.php
@@ -692,11 +692,13 @@
        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() );
                        }
diff --git a/includes/Revision.php b/includes/Revision.php
index 208652f..8f337f9 100644
--- a/includes/Revision.php
+++ b/includes/Revision.php
@@ -20,6 +20,7 @@
  * @file
  */
 use MediaWiki\Linker\LinkTarget;
+use MediaWiki\MediaWikiServices;
 
 /**
  * @todo document
@@ -1902,7 +1903,7 @@
         * @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 ),
diff --git a/includes/actions/InfoAction.php b/includes/actions/InfoAction.php
index 4d80a1c..c039388 100644
--- a/includes/actions/InfoAction.php
+++ b/includes/actions/InfoAction.php
@@ -690,7 +690,6 @@
 
                                $dbr = wfGetDB( DB_REPLICA );
                                $dbrWatchlist = wfGetDB( DB_REPLICA, 
'watchlist' );
-
                                $setOpts += Database::getCacheSetOptions( $dbr, 
$dbrWatchlist );
 
                                $watchedItemStore = 
MediaWikiServices::getInstance()->getWatchedItemStore();
diff --git a/includes/libs/objectcache/WANObjectCache.php 
b/includes/libs/objectcache/WANObjectCache.php
index b0a3109..e7c4edb 100644
--- a/includes/libs/objectcache/WANObjectCache.php
+++ b/includes/libs/objectcache/WANObjectCache.php
@@ -939,12 +939,13 @@
                $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;
                }
@@ -1013,8 +1014,10 @@
                }
 
                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 );
                }
 
@@ -1336,10 +1339,11 @@
         * @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;
diff --git a/includes/libs/rdbms/database/Database.php 
b/includes/libs/rdbms/database/Database.php
index fc55671..a5a170b 100644
--- a/includes/libs/rdbms/database/Database.php
+++ b/includes/libs/rdbms/database/Database.php
@@ -50,8 +50,8 @@
 
        /** @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 */
@@ -511,11 +511,11 @@
        }
 
        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() {
@@ -820,7 +820,7 @@
                                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.
@@ -2751,7 +2751,7 @@
                $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 );
                }

-- 
To view, visit https://gerrit.wikimedia.org/r/315998
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I45856b210c289c2e2f193cc4328a208e20b4e0a8
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Krinkle <krinklem...@gmail.com>
Gerrit-Reviewer: Ori.livneh <o...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to