From 7b9edd6233e3869eddbe826b36097048150da583 Mon Sep 17 00:00:00 2001 From: catch <catch@35733.no-reply.drupal.org> Date: Thu, 17 Nov 2022 11:02:34 +0000 Subject: [PATCH] Issue #3164428 by DonAtt, longwave, sahil.goyal, Anchal_gupta, alexpott: Use cacheBackend->setMultiple in ContentEntityStorageBase::setPersistentCache --- .../Drupal/Core/Entity/ContentEntityStorageBase.php | 7 ++++++- .../Core/Entity/Sql/SqlContentEntityStorageTest.php | 10 +++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php index 17a5d3bfdb86..7e18e5bca1f4 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php @@ -1113,9 +1113,14 @@ protected function setPersistentCache($entities) { $this->entityTypeId . '_values', 'entity_field_info', ]; + $items = []; foreach ($entities as $id => $entity) { - $this->cacheBackend->set($this->buildCacheId($id), $entity, CacheBackendInterface::CACHE_PERMANENT, $cache_tags); + $items[$this->buildCacheId($id)] = [ + 'data' => $entity, + 'tags' => $cache_tags, + ]; } + $this->cacheBackend->setMultiple($items); } /** diff --git a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php index 185a68eda056..f256245a6786 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php @@ -7,7 +7,6 @@ namespace Drupal\Tests\Core\Entity\Sql; -use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Cache\MemoryCache\MemoryCache; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\Entity\EntityFieldManager; @@ -1296,8 +1295,13 @@ public function testLoadMultiplePersistentCacheMiss() { ->with([$key]) ->willReturn([]); $this->cache->expects($this->once()) - ->method('set') - ->with($key, $entity, CacheBackendInterface::CACHE_PERMANENT, [$this->entityTypeId . '_values', 'entity_field_info']); + ->method('setMultiple') + ->with([ + $key => [ + 'data' => $entity, + 'tags' => [$this->entityTypeId . '_values', 'entity_field_info'], + ], + ]); $this->entityTypeManager->expects($this->any()) ->method('getActiveDefinition') -- GitLab