Skip to content

Commit

Permalink
Moved the caching of the calculated value to the collector
Browse files Browse the repository at this point in the history
Caching the value because of the calculation should not be the
responsibility of the template.
  • Loading branch information
stof committed Oct 2, 2012
1 parent 2442847 commit d8f2347
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 6 additions & 1 deletion DataCollector/DoctrineDataCollector.php
Expand Up @@ -28,6 +28,7 @@
class DoctrineDataCollector extends BaseCollector
{
private $registry;
private $invalidEntityCount;

public function __construct(ManagerRegistry $registry)
{
Expand Down Expand Up @@ -79,6 +80,10 @@ public function getMappingErrors()

public function getInvalidEntityCount()
{
return array_sum(array_map('count', $this->data['errors']));
if (null === $this->invalidEntityCount) {
$this->invalidEntityCount = array_sum(array_map('count', $this->data['errors']));
}

return $this->invalidEntityCount;
}
}
5 changes: 1 addition & 4 deletions Resources/views/Collector/db.html.twig
Expand Up @@ -15,12 +15,9 @@
<b>Query time</b>
<span>{{ '%0.2f'|format(collector.time * 1000) }} ms</span>
</div>

{%- set invalid_entity_count = collector.invalidEntityCount -%}

<div class="sf-toolbar-info-piece">
<b>Invalid entities</b>
<span class="sf-toolbar-status sf-toolbar-status-{{ invalid_entity_count > 0 ? 'red' : 'green' }}">{{ invalid_entity_count }}</span>
<span class="sf-toolbar-status sf-toolbar-status-{{ collector.invalidEntityCount > 0 ? 'red' : 'green' }}">{{ collector.invalidEntityCount }}</span>
</div>
{% endset %}
{% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with { 'link': profiler_url } %}
Expand Down

0 comments on commit d8f2347

Please sign in to comment.