From 7bffa1f49e1a559baacb99be30031f96cc023b1e Mon Sep 17 00:00:00 2001 From: Andrey Savchenko Date: Sun, 24 Mar 2019 21:20:55 +0200 Subject: [PATCH] Added plotting of early SQL queries (WP 5.1+) Fixes #19 --- CHANGELOG.md | 3 +++ src/Record/Collector/Sql_Collector.php | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8c966f..ef91704 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/Record/Collector/Sql_Collector.php b/src/Record/Collector/Sql_Collector.php index d11a048..4939f01 100644 --- a/src/Record/Collector/Sql_Collector.php +++ b/src/Record/Collector/Sql_Collector.php @@ -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' ) ) {