From db5e7aee95bbfb116e0943cfa7ad7d2219620a03 Mon Sep 17 00:00:00 2001
From: catch <6915-catch@users.noreply.drupalcode.org>
Date: Wed, 28 May 2025 22:33:36 +0100
Subject: [PATCH] Issue #3520750 by alexpott: Use a transaction
 PoDatabaseWriter to improve performance

(cherry picked from commit c15eed328edae78710d150863a140bbd66aa2593)
---
 core/modules/locale/src/PoDatabaseWriter.php | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/core/modules/locale/src/PoDatabaseWriter.php b/core/modules/locale/src/PoDatabaseWriter.php
index 7e7340cf1070..436d710d7bad 100644
--- a/core/modules/locale/src/PoDatabaseWriter.php
+++ b/core/modules/locale/src/PoDatabaseWriter.php
@@ -198,10 +198,15 @@ public function writeItem(PoItem $item) {
    * {@inheritdoc}
    */
   public function writeItems(PoReaderInterface $reader, $count = -1) {
+    // Processing multiple writes in a transaction is quicker than committing
+    // each individual write.
+    $transaction = \Drupal::database()->startTransaction();
     $forever = $count == -1;
     while (($count-- > 0 || $forever) && ($item = $reader->readItem())) {
       $this->writeItem($item);
     }
+    // Commit the transaction.
+    unset($transaction);
   }
 
   /**
-- 
GitLab