Added plotting of early SQL queries (WP 5.1+)

Fixes #19
This commit is contained in:
Andrey Savchenko committed 2019-03-24 21:20:55 +02:00
1 parent ba72763486
commit 7bffa1f49e
2 files changed
+6 -3

No files matched your search

+3
View File
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## Unreleased
### Added
- plotting of early SQL queries (WP 5.1+)
### Changed
- unit tests for PHPUnit 8
+3 -3
View File
@@ -25,7 +25,7 @@ class Sql_Collector implements Record_Collector_Interface {
$this->formatter = new Backtrace_Formatter();
if ( $this->is_savequeries() ) {
add_filter( 'query', [ $this, 'query' ], 20 ); // TODO refactor when core provides time start data in 5.0.
add_filter( 'query', [ $this, 'query' ], 20 ); // TODO Drop recording time if dropping support for WP <5.1.
}
}
@@ -80,7 +80,7 @@ class Sql_Collector implements Record_Collector_Interface {
*
* @param int $key Query key in captured data.
* @param array $query_data Array of captured query data.
* @psalm-param array{0: string, 1: float, 2: string} $query_data
* @psalm-param array{0: string, 1: float, 2: string, 3: float} $query_data
*
* @return Record
*/
@@ -91,7 +91,7 @@ class Sql_Collector implements Record_Collector_Interface {
[ $sql, $duration, $caller ] = $query_data;
/** @var float $query_start */
$query_start = $this->query_starts[ $key ] ?? $last_query_end;
$query_start = $query_data[3] ?? $this->query_starts[ $key ] ?? $last_query_end;
$sql = trim( $sql );
$category = 'sql-read';
if ( 0 === stripos( $sql, 'INSERT' ) || 0 === stripos( $sql, 'UPDATE' ) ) {