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/data/%27%20.%20mediabox_timestamp%28find_in_path%28%27javascript/%7B%24www_url%7Dadmin/compta/operations/%40%20%27info_etape_suivante_2%27%20=%3E%20%27You%20can%20move%20on%20to%20the%20next%20step.%27%2C%20%27info_exceptions_proxy%27%20=%3E%20%27Exceptions%20for%20the%20proxy%27%2C%20%27info_exportation_base%27%20=%3E%20%27export%20database%20to%20%40archive%40%27%2C-%27info_facilite_suivi_activite%27%20=%3E%20%27To%20simplify%20monitoring%20of%20the%20site/%27s%20editorial;-%20%20activities%2C%20SPIP%20can%20send%20rmail%20notifications%2C%20e.g.%20to%20an%20editors/%27.%28%24current%20%3E%202?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() ); }