From de516758aa4c076520332733361077dc745d239a Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 10 Apr 2019 21:40:16 -0700 Subject: [PATCH] rdbms: optimize DBConnRef::getType() to avoid connections when possible Change-Id: Ibe7f2ab173ba1457b6b11c4fe37e599962ae51b0 --- includes/libs/rdbms/database/DBConnRef.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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() ); } -- 2.20.1