rdbms: migrate DatabaseMysqlBase::getServerVersion() to using the local server cache
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 4 Sep 2019 02:47:35 +0000 (19:47 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Wed, 4 Sep 2019 03:24:56 +0000 (20:24 -0700)
Change-Id: If667f761b2173226ccf1129ec864d1ce9729024a

includes/libs/rdbms/database/DatabaseMysqlBase.php

index 851a178..7be3b7d 100644 (file)
@@ -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 );
+                       }
+               );
        }
 
        /**