commit 22721a9b1f9dc7ceaa339320e561814a2ab23868 Author: Lee Rowlands Date: Wed Sep 23 09:10:52 2015 +1000 p2 diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 8100474..f462fb9 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -358,7 +358,8 @@ function comment_entity_storage_load($entities, $entity_type) { // the values are actually about to be used. /* @var \Drupal\comment\CommentStatisticsLazyLoaderInterface $loader */ $loader = \Drupal::service('comment.statistics_lazy_loader'); - $loader->recordEntitiesToLoad($entity_type, array_keys($entities)); + $entity_ids = array_keys($entities); + $loader->recordEntitiesToLoad($entity_type, array_combine($entity_ids, $entity_ids)); } /** diff --git a/core/modules/comment/src/CommentStatisticsLazyLoader.php b/core/modules/comment/src/CommentStatisticsLazyLoader.php index 8dd8e68..8f8d9ae 100644 --- a/core/modules/comment/src/CommentStatisticsLazyLoader.php +++ b/core/modules/comment/src/CommentStatisticsLazyLoader.php @@ -51,7 +51,7 @@ public function recordEntitiesToLoad($entity_type_id, array $entity_ids) { if (!isset($this->entitiesToLoad[$entity_type_id])) { $this->entitiesToLoad[$entity_type_id] = []; } - $this->entitiesToLoad[$entity_type_id] = array_unique($this->entitiesToLoad[$entity_type_id], $entity_ids); + $this->entitiesToLoad[$entity_type_id] += $entity_ids; return $this; } @@ -60,7 +60,15 @@ public function recordEntitiesToLoad($entity_type_id, array $entity_ids) { */ public function loadStatistics(EntityInterface $entity, $statistics_field_name) { $entity_type_id = $entity->getEntityTypeId(); - if (!isset($this->loadedValues[$entity_type_id][$entity->id()])) { + if (!isset($this->loadedValues[$entity_type_id])) { + // Initialize this entity-type. + $this->loadedValues[$entity_type_id] = []; + } + // Make sure the requested entity is also in the stack. + if (!isset($this->entitiesToLoad[$entity_type_id][$entity->id()])) { + $this->entitiesToLoad[$entity_type_id][$entity->id()] = $entity->id(); + } + if (!isset($this->loadedValues[$entity_type_id][$entity->id()]) && $this->entitiesToLoad[$entity_type_id]) { $this->loadedValues[$entity_type_id] += $this->commentStatistics->read($this->entitiesToLoad[$entity_type_id], $entity_type_id); } if (!isset($this->loadedValues[$entity_type_id][$entity->id()])) { diff --git a/core/modules/comment/src/Plugin/Field/DataType/CommentStatisticsIntegerData.php b/core/modules/comment/src/Plugin/DataType/CommentStatisticsIntegerData.php similarity index 93% rename from core/modules/comment/src/Plugin/Field/DataType/CommentStatisticsIntegerData.php rename to core/modules/comment/src/Plugin/DataType/CommentStatisticsIntegerData.php index beb6dbd..57fb771 100644 --- a/core/modules/comment/src/Plugin/Field/DataType/CommentStatisticsIntegerData.php +++ b/core/modules/comment/src/Plugin/DataType/CommentStatisticsIntegerData.php @@ -37,7 +37,7 @@ public function getCastedValue() { */ public function getValue() { if (!isset($this->value)) { - $this->value = $this->getCommentStatisticsLazyLoader()->loadStatistics($this->getRoot(), $this->getName()); + $this->value = $this->getCommentStatisticsLazyLoader()->loadStatistics($this->getRoot()->getValue(), $this->getName()); } return parent::getValue(); } diff --git a/core/modules/comment/src/Plugin/Field/DataType/CommentStatisticsStringData.php b/core/modules/comment/src/Plugin/DataType/CommentStatisticsStringData.php similarity index 92% rename from core/modules/comment/src/Plugin/Field/DataType/CommentStatisticsStringData.php rename to core/modules/comment/src/Plugin/DataType/CommentStatisticsStringData.php index 5641c91..5047eaf 100644 --- a/core/modules/comment/src/Plugin/Field/DataType/CommentStatisticsStringData.php +++ b/core/modules/comment/src/Plugin/DataType/CommentStatisticsStringData.php @@ -31,7 +31,7 @@ class CommentStatisticsStringData extends StringData { */ public function getValue() { if (!isset($this->value)) { - $this->value = $this->getCommentStatisticsLazyLoader()->loadStatistics($this->getRoot(), $this->getName()); + $this->value = $this->getCommentStatisticsLazyLoader()->loadStatistics($this->getRoot()->getValue(), $this->getName()); } return parent::getValue(); }