@@ -192,19 +192,35 @@ static function (): void {
192
192
array (
193
193
'measure_callback ' => static function ( $ metric ): void {
194
194
// This global should typically be set when this is called, but check just in case.
195
- if ( ! isset ( $ GLOBALS ['perflab_query_time_before_template ' ] ) ) {
195
+ if ( ! isset ( $ GLOBALS ['perflab_query_time_before_template ' ] ) || ! is_float ( $ GLOBALS [ ' perflab_query_time_before_template ' ] ) ) {
196
196
return ;
197
197
}
198
198
199
199
// This should never happen, but some odd database implementations may be doing it wrong.
200
200
if ( ! isset ( $ GLOBALS ['wpdb ' ]->queries ) || ! is_array ( $ GLOBALS ['wpdb ' ]->queries ) ) {
201
+ // A notice is already emitted above, but if $perflab_query_time_before_template was not
202
+ // set, then this condition wouldn't be checked in the first place.
201
203
return ;
202
204
}
203
205
206
+ /**
207
+ * Query times.
208
+ *
209
+ * @var float[] $query_times
210
+ */
211
+ $ query_times = array ();
212
+ foreach ( $ GLOBALS ['wpdb ' ]->queries as $ query ) {
213
+ if ( ! is_array ( $ query ) || ! isset ( $ query [1 ] ) || ! is_float ( $ query [1 ] ) ) {
214
+ // A notice is already emitted above.
215
+ return ;
216
+ }
217
+ $ query_times [] = $ query [1 ];
218
+ }
219
+
204
220
$ total_query_time = array_reduce (
205
- $ GLOBALS [ ' wpdb ' ]-> queries ,
206
- static function ( $ acc , $ query ) {
207
- return $ acc + $ query [ 1 ] ;
221
+ $ query_times ,
222
+ static function ( float $ acc , float $ query_time ): float {
223
+ return $ acc + $ query_time ;
208
224
},
209
225
0.0
210
226
);
0 commit comments