Browse files

Moved the caching of the calculated value to the collector

Caching the value because of the calculation should not be the
responsibility of the template.
  • Loading branch information...
1 parent 2442847 commit d8f23474c2a1e0aeb63e54fddd9f2cf362b96ac0 @stof stof committed Oct 3, 2012
Showing with 7 additions and 5 deletions.
  1. +6 −1 DataCollector/DoctrineDataCollector.php
  2. +1 −4 Resources/views/Collector/db.html.twig
View
7 DataCollector/DoctrineDataCollector.php
@@ -28,6 +28,7 @@
class DoctrineDataCollector extends BaseCollector
{
private $registry;
+ private $invalidEntityCount;
public function __construct(ManagerRegistry $registry)
{
@@ -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;
}
}
View
5 Resources/views/Collector/db.html.twig
@@ -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 } %}

0 comments on commit d8f2347

Please sign in to comment.