From a4095b9b33758b86e43862c07145f30084b633f2 Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Thu, 4 Feb 2021 15:01:08 +0000
Subject: [PATCH] Issue #2558857 by heddn, andr1yun, grahl, andypost, catch,
 benjifisher, Berdir, joachim: Migrations invalidate entity caches when trying
 to reclaim memory, should flush

---
 core/modules/migrate/src/MigrateExecutable.php | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/core/modules/migrate/src/MigrateExecutable.php b/core/modules/migrate/src/MigrateExecutable.php
index 4f75c9486e51..4f9dde709715 100644
--- a/core/modules/migrate/src/MigrateExecutable.php
+++ b/core/modules/migrate/src/MigrateExecutable.php
@@ -552,11 +552,8 @@ protected function attemptMemoryReclaim() {
     // plenty of memory to continue.
     drupal_static_reset();
 
-    // Entity storage can blow up with caches so clear them out.
-    $entity_type_manager = \Drupal::entityTypeManager();
-    foreach ($entity_type_manager->getDefinitions() as $id => $definition) {
-      $entity_type_manager->getStorage($id)->resetCache();
-    }
+    // Entity storage can blow up with caches, so clear it out.
+    \Drupal::service('entity.memory_cache')->deleteAll();
 
     // @TODO: explore resetting the container.
 
-- 
GitLab