From: Aaron Schulz Date: Thu, 11 Apr 2019 04:40:16 +0000 (-0700) Subject: rdbms: optimize DBConnRef::getType() to avoid connections when possible X-Git-Tag: 1.34.0-rc.0~2041^2 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=de516758aa4c076520332733361077dc745d239a;p=lhc%2Fweb%2Fwiklou.git rdbms: optimize DBConnRef::getType() to avoid connections when possible Change-Id: Ibe7f2ab173ba1457b6b11c4fe37e599962ae51b0 --- diff --git a/includes/libs/rdbms/database/DBConnRef.php b/includes/libs/rdbms/database/DBConnRef.php index a06ce76fa5..b216892486 100644 --- a/includes/libs/rdbms/database/DBConnRef.php +++ b/includes/libs/rdbms/database/DBConnRef.php @@ -211,6 +211,19 @@ class DBConnRef implements IDatabase { } public function getType() { + if ( $this->conn === null ) { + // Avoid triggering a database connection + if ( $this->params[self::FLD_INDEX] === ILoadBalancer::DB_MASTER ) { + $index = $this->lb->getWriterIndex(); + } else { + $index = $this->params[self::FLD_INDEX]; + } + if ( $index >= 0 ) { + // In theory, if $index is DB_REPLICA, the type could vary + return $this->lb->getServerType( $index ); + } + } + return $this->__call( __FUNCTION__, func_get_args() ); }