Skip to content

Commit

Permalink
checks if collectors are available
Browse files Browse the repository at this point in the history
  • Loading branch information
lekoala committed Mar 7, 2021
1 parent 2a25756 commit f254adf
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
16 changes: 9 additions & 7 deletions code/Collector/DatabaseCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ public function collect()
if ($dbQueryWarningLevel && $data['nb_statements'] > $dbQueryWarningLevel) {
$helpLink = DebugBar::config()->get('performance_guide_link');
$messages = DebugBar::getMessageCollector();
$messages->addMessage(
"This page ran more than $dbQueryWarningLevel database queries." .
"\nYou could reduce this by implementing caching." .
"\nYou can find more info here: $helpLink",
'warning',
true
);
if ($messages) {
$messages->addMessage(
"This page ran more than $dbQueryWarningLevel database queries." .
"\nYou could reduce this by implementing caching." .
"\nYou can find more info here: $helpLink",
'warning',
true
);
}
}

return $data;
Expand Down
16 changes: 12 additions & 4 deletions code/DebugBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -564,19 +564,27 @@ public static function getRequest()
}

/**
* @return TimeDataCollector
* @return TimeDataCollector|false
*/
public static function getTimeCollector()
{
return self::getDebugBar()->getCollector('time');
$debugbar = self::getDebugBar();
if (!$debugbar) {
return false;
}
return $debugbar->getCollector('time');
}

/**
* @return MessagesCollector
* @return MessagesCollector|false
*/
public static function getMessageCollector()
{
return self::getDebugBar()->getCollector('messages');
$debugbar = self::getDebugBar();
if (!$debugbar) {
return false;
}
return $debugbar->getCollector('messages');
}

/**
Expand Down
16 changes: 9 additions & 7 deletions code/Proxy/SSViewerProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ public function process($item, $arguments = null, $inheritedScope = null)
if ($templateRenderWarningLevel && $totalTime > $templateRenderWarningLevel) {
$sourceFile = $this->getCacheFile($this->chosen);
$messages = DebugBar::getMessageCollector();
$messages->addMessage(
"The template $templateName needed $totalTime seconds to render." .
"\nYou could reduce this by implementing partial caching." .
"\nYou can also check the cache file : $sourceFile",
'warning',
true
);
if ($messages) {
$messages->addMessage(
"The template $templateName needed $totalTime seconds to render." .
"\nYou could reduce this by implementing partial caching." .
"\nYou can also check the cache file : $sourceFile",
'warning',
true
);
}
}

return $result;
Expand Down

0 comments on commit f254adf

Please sign in to comment.