Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: front page takes 50 mysql queries


_ck_
Participant

@_ck_

Ah I totally forgot I’ve got visitor tracking which adds some calls but doesn’t explain why it’s more than a dozen calls by design.

If anyone’s interested, I’ve ported the “query diagnostics” plugin from wordpress so you can see each mysql call used, hidden as a report at the end of each page (for administrators).

<?php

/*
Plugin Name: bb-benchmark
Plugin URI: http://CKon.WordPress.com
Version: 0.10
Description: Prints simple benchmarks and mysql diagnostics, hidden in page footers.
based on Jerome Lavigne's Query Diagnostics for WordPress http://vapourtrails.ca/wp-plugins
Author: _ck_
Author URI: http://CKon.WordPress.com
*/

/* INSTRUCTIONS:

1. add this line to your bbpress config.php file: @define('SAVEQUERIES', true);
2. install & activate plugin
3. do a "view source" on any bbpress page to see hidden results at bottom

*/

function bb_benchmark_output() {
if (bb_current_user_can( 'administrate' ) ) :
if (SAVEQUERIES) :
global $bbdb;
echo "<!-- n === benchmark & query results === n ";

while($qposition < $bbdb->num_queries){
$qsubtime=$bbdb->queries[$qposition][1];
if ($qsubtime>$qmaxtime) {$qmaxtime=$qsubtime;$qmaxquery=$bbdb->queries[$qposition][0];}
$qtotal += $qsubtime;
$qposition++;
}

$timer_stop=bb_timer_stop(0);

echo @shell_exec("uptime")."n";
echo "query count: ".$bbdb->num_queries." nn";
echo "total query time: ".round($qtotal,4)." seconds nn";
echo "total page time: ".round($timer_stop,4)." seconds.nn";
echo "page render difference: ".(round($timer_stop-$qtotal,4))." seconds nn";
echo "slowest call was: ".$qmaxquery."n at ".round($qmaxtime,4)." seconds nn";

if (phpversion() >5.0 && function_exists(memory_get_peak_usage()) && function_exists(memory_get_usage())) {
echo "nn === memory usage === n";
echo "peak memory ".memory_get_peak_usage()." nn";
echo "total memory ".memory_get_usage()." nn";
}

// echo "nn === resource usage === n";
// print_r (getrusage());

echo "nn === mysql queries used === n";
print_r($bbdb->queries);

echo "-->";
endif;
endif;
}

add_action('bb_foot', 'bb_benchmark_output');

?>

Skip to toolbar