From: Aaron Schulz Date: Thu, 22 Dec 2016 23:16:07 +0000 (-0800) Subject: Avoid starting transactions in getHeartbeatData() X-Git-Tag: 1.31.0-rc.0~4407^2 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/cotisations/gestion/rappel_modifier.php?a=commitdiff_plain;h=22ac7bac9e7027099f3523f5d63fb8a34109d218;p=lhc%2Fweb%2Fwiklou.git Avoid starting transactions in getHeartbeatData() This can avoid excess round trips in LoadBalancer::getLagTimes() Change-Id: Ibe9558cc825c5a0dd03ea109926ff15d00c60e31 --- diff --git a/includes/libs/rdbms/database/DatabaseMysqlBase.php b/includes/libs/rdbms/database/DatabaseMysqlBase.php index 668443ba76..5d680e21f0 100644 --- a/includes/libs/rdbms/database/DatabaseMysqlBase.php +++ b/includes/libs/rdbms/database/DatabaseMysqlBase.php @@ -756,14 +756,20 @@ abstract class DatabaseMysqlBase extends Database { * @see https://www.percona.com/doc/percona-toolkit/2.1/pt-heartbeat.html */ protected function getHeartbeatData( array $conds ) { - $whereSQL = $this->makeList( $conds, self::LIST_AND ); - // Use ORDER BY for channel based queries since that field might not be UNIQUE. - // Note: this would use "TIMESTAMPDIFF(MICROSECOND,ts,UTC_TIMESTAMP(6))" but the - // percision field is not supported in MySQL <= 5.5. - $res = $this->query( - "SELECT ts FROM heartbeat.heartbeat WHERE $whereSQL ORDER BY ts DESC LIMIT 1" - ); - $row = $res ? $res->fetchObject() : false; + // Do not bother starting implicit transactions here + $this->clearFlag( self::DBO_TRX, self::REMEMBER_PRIOR ); + try { + $whereSQL = $this->makeList( $conds, self::LIST_AND ); + // Use ORDER BY for channel based queries since that field might not be UNIQUE. + // Note: this would use "TIMESTAMPDIFF(MICROSECOND,ts,UTC_TIMESTAMP(6))" but the + // percision field is not supported in MySQL <= 5.5. + $res = $this->query( + "SELECT ts FROM heartbeat.heartbeat WHERE $whereSQL ORDER BY ts DESC LIMIT 1" + ); + $row = $res ? $res->fetchObject() : false; + } finally { + $this->restoreFlags(); + } return [ $row ? $row->ts : null, microtime( true ) ]; }