From 7280680928e71f8caa6ba89384d7a83f035d64e9 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Wed, 7 Dec 2011 00:51:15 +0000 Subject: [PATCH] 2.1.3 Remove QM_DB_LONG (pretty pointless) Fix display of wp_admin_bar instantiated queries Fix function trace for HTTP calls and transients --- components/db_queries.php | 61 +++++++++++++++------------------------ components/http.php | 4 +-- components/transients.php | 4 +-- query-monitor.php | 2 +- wp-content/db.php | 2 +- 5 files changed, 29 insertions(+), 44 deletions(-) diff --git a/components/db_queries.php b/components/db_queries.php index 30f4c7c5e..97fec3d63 100644 --- a/components/db_queries.php +++ b/components/db_queries.php @@ -4,8 +4,6 @@ define( 'SAVEQUERIES', true ); if ( !defined( 'QM_DB_EXPENSIVE' ) ) define( 'QM_DB_EXPENSIVE', 0.05 ); -if ( !defined( 'QM_DB_LONG' ) ) - define( 'QM_DB_LONG', 1000 ); if ( !defined( 'QM_DB_LIMIT' ) ) define( 'QM_DB_LIMIT', 100 ); @@ -117,18 +115,15 @@ function add_func_time( $func, $ltime ) { function process_db_object( $id, $db ) { - $rows = array(); - $total_time = 0; - $total_qs = 0; - $ignored_time = 0; - $has_results = false; + $rows = array(); + $total_time = 0; + $total_qs = 0; + $has_results = false; foreach ( (array) $db->queries as $query ) { - /* ********************************************************* */ - #if ( false !== strpos( $query[2], 'wp_admin_bar' ) ) - # continue; - /* ********************************************************* */ + if ( false !== strpos( $query[2], 'wp_admin_bar' ) and !isset( $_REQUEST['qm_display_all'] ) ) + continue; $sql = $query[0]; $ltime = $query[1]; @@ -140,24 +135,15 @@ function process_db_object( $id, $db ) { else $result = null; - if ( strpos( $funcs, 'wp_admin_bar' ) ) { - $ignored_time += $ltime; - } else { - $total_time += $ltime; - $total_qs++; - } + $total_time += $ltime; + $total_qs++; if ( !empty( $funcs ) ) $func = reset( array_reverse( explode( ', ', $funcs ) ) ); else $func = '' . __( 'none', 'query_monitor' ) . ''; - if ( strpos( $funcs, 'wp_admin_bar' ) ) { - if ( isset( $_REQUEST['qm_display_all'] ) ) - $this->add_func_time( $func, $ltime ); - } else { - $this->add_func_time( $func, $ltime ); - } + $this->add_func_time( $func, $ltime ); $sql = str_replace( array( "\r\n", "\r", "\n", "\t" ), ' ', $sql ); $sql = esc_html( trim( $sql ) ); @@ -217,7 +203,13 @@ function output_queries( $name, $db ) { echo ''; if ( $max_exceeded ) { - echo '' . sprintf( __( '%1$s %2$s queries were performed on this page load. Only the first %3$d are shown below. Total query time and cumulative function times should be accurate.', 'query_monitor' ), number_format_i18n( $total_qs ), $name, number_format_i18n( QM_DB_LIMIT ) ) . ''; + echo ''; + echo '' . sprintf( __( '%1$s %2$s queries were performed on this page load. Only the first %3$d are shown. Total times shown are for all queries.', 'query_monitor' ), + number_format_i18n( $total_qs ), + $name, + number_format_i18n( QM_DB_LIMIT ) + ) . ''; + echo ''; } echo ''; @@ -237,23 +229,16 @@ function output_queries( $name, $db ) { if ( !empty( $rows ) ) { - foreach ( $rows as $row ) { - if ( strpos( $row['funcs'], 'wp_admin_bar' ) ) { - if ( !isset( $_REQUEST['qm_display_all'] ) ) - continue; - $row_class = 'qm-na'; - } else { - $row_class = ''; - } + foreach ( $rows as $i => $row ) { + + if ( $i === QM_DB_LIMIT ) + break; + + $row_class = ''; $select = ( 0 === strpos( strtoupper( $row['sql'] ), 'SELECT' ) ); $ql = strlen( $row['sql'] ); - $qs = size_format( $ql ); $stime = number_format_i18n( $row['ltime'], 4 ); $ltime = number_format_i18n( $row['ltime'], 10 ); - if ( $select and ( $ql > QM_DB_LONG ) ) - $row['qs'] = "
({$qs})"; - else - $row['qs'] = ''; $td = ( $row['ltime'] > QM_DB_EXPENSIVE ) ? " class='qm-expensive'" : ''; if ( !$select ) $row['sql'] = "{$row['sql']}"; @@ -274,7 +259,7 @@ function output_queries( $name, $db ) { echo " \n - {$row['sql']}{$row['qs']}\n + {$row['sql']}\n {$row['func']}\n {$results} {$stime}\n diff --git a/components/http.php b/components/http.php index e04860969..ca342d09b 100644 --- a/components/http.php +++ b/components/http.php @@ -151,8 +151,8 @@ function output( $args, $data ) { '
 ? ', ' = ', ), $row['url'] ); - unset( $row['trace'][0], $row['trace'][1], $row['trace'][2], $row['trace'][3] ); - $f = 4; + unset( $row['trace'][0], $row['trace'][1], $row['trace'][2] ); + $f = 6; $func = $row['trace'][$f]; if ( 0 === strpos( $func, 'SimplePie' ) ) $func = $row['trace'][++$f]; diff --git a/components/transients.php b/components/transients.php index ed4a73c5b..bbbd76bc3 100644 --- a/components/transients.php +++ b/components/transients.php @@ -43,8 +43,8 @@ function output( $args, $data ) { if ( !empty( $data['trans'] ) ) { foreach ( $data['trans'] as $row ) { - unset( $row['trace'][0], $row['trace'][1] ); - $func = $row['trace'][2]; + unset( $row['trace'][0], $row['trace'][1], $row['trace'][2], $row['trace'][3] ); + $func = $row['trace'][5]; $transient = str_replace( array( '_site_transient_', '_transient_' diff --git a/query-monitor.php b/query-monitor.php index cca8aa21b..77b7a9c66 100644 --- a/query-monitor.php +++ b/query-monitor.php @@ -2,7 +2,7 @@ /* Plugin Name: Query Monitor Description: Monitoring of database queries, hooks, conditionals and much more. -Version: 2.1.2 +Version: 2.1.3 Author: John Blackbourn Author URI: http://lud.icro.us/ diff --git a/wp-content/db.php b/wp-content/db.php index cbb111375..402893ad9 100644 --- a/wp-content/db.php +++ b/wp-content/db.php @@ -1,7 +1,7 @@