From 982d493a4cd3d570ff50be169df9be07600e2d11 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 3 Sep 2019 19:47:35 -0700 Subject: [PATCH] rdbms: migrate DatabaseMysqlBase::getServerVersion() to using the local server cache Change-Id: If667f761b2173226ccf1129ec864d1ce9729024a --- .../libs/rdbms/database/DatabaseMysqlBase.php | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/includes/libs/rdbms/database/DatabaseMysqlBase.php b/includes/libs/rdbms/database/DatabaseMysqlBase.php index 851a178eb4..7be3b7d99d 100644 --- a/includes/libs/rdbms/database/DatabaseMysqlBase.php +++ b/includes/libs/rdbms/database/DatabaseMysqlBase.php @@ -64,8 +64,6 @@ abstract class DatabaseMysqlBase extends Database { /** @var bool|null */ protected $defaultBigSelects = null; - /** @var string|null */ - private $serverVersion = null; /** @var bool|null */ private $insertSelectIsSafe = null; /** @var stdClass|null */ @@ -1102,13 +1100,19 @@ abstract class DatabaseMysqlBase extends Database { * @return string */ public function getServerVersion() { - // Not using mysql_get_server_info() or similar for consistency: in the handshake, - // MariaDB 10 adds the prefix "5.5.5-", and only some newer client libraries strip - // it off (see RPL_VERSION_HACK in include/mysql_com.h). - if ( $this->serverVersion === null ) { - $this->serverVersion = $this->selectField( '', 'VERSION()', '', __METHOD__ ); - } - return $this->serverVersion; + $cache = $this->srvCache; + $fname = __METHOD__; + + return $cache->getWithSetCallback( + $cache->makeGlobalKey( 'mysql-server-version', $this->getServer() ), + $cache::TTL_HOUR, + function () use ( $fname ) { + // Not using mysql_get_server_info() or similar for consistency: in the handshake, + // MariaDB 10 adds the prefix "5.5.5-", and only some newer client libraries strip + // it off (see RPL_VERSION_HACK in include/mysql_com.h). + return $this->selectField( '', 'VERSION()', '', $fname ); + } + ); } /** -- 2.20.1