XF 1.2 Query count higher on debug page than in footer?

alexp999

Active member
I am just in the process of trying to make my site as lean as possible before it goes live, so I have enabled debug mode to try and see if there are any extra queries I could reduce and I have noticed that on say the forum index, the footer will say 10 queries, but when you click on it, the debug page says there are 14.

Any idea why the debug page would show more queries?
 
The debug query count is being fetched and set to the template, BEFORE all operations are finished.
All the events executed after calling $template->setParams(XenForo_Debug::getDebugTemplateParams()); won't be counted to the query count :(.

If you want the REAL query count, you need to call XenForo_Application::getDb()->getProfiler()->getTotalNumQueries(); as LAST operation, just before the response is being sent to the client and output the phrase (I'm using an event listener on front_controller_post_view to get the REAL query count)
PHP:
    public static function frontControllerPostView(XenForo_FrontController $fc, &$output){

        if ($fc->getDependencies() instanceof XenForo_Dependencies_Public){
            $search = '$STATUSCODE$';
            $code = $fc->getResponse()->getHttpResponseCode();

            $color = 'green';
            switch ($code){
                case 404:
                    $color = 'red';
                    break;
            }
            $allQueries = XenForo_Application::getDb()->getProfiler()->getTotalNumQueries();
            $output = str_replace('$ALLQUERIES$', $allQueries, $output);
            $output = str_replace('$STATUSCOLOR$',$color,$output);
            $output = str_replace($search,$code,$output);
        }
    }
 
Last edited:
Back
Top Bottom