From: Aaron Schulz Date: Wed, 4 Sep 2019 02:47:35 +0000 (-0700) Subject: rdbms: migrate DatabaseMysqlBase::getServerVersion() to using the local server cache X-Git-Tag: 1.34.0-rc.0~391^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/File:%2A_image6?a=commitdiff_plain;h=982d493a4cd3d570ff50be169df9be07600e2d11;p=lhc%2Fweb%2Fwiklou.git rdbms: migrate DatabaseMysqlBase::getServerVersion() to using the local server cache Change-Id: If667f761b2173226ccf1129ec864d1ce9729024a --- 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 ); + } + ); } /**