From 42016239637fbe182a71d12bc2f760d4c95d8e51 Mon Sep 17 00:00:00 2001
From: Andreas Fernandez <a.fernandez@scripting-base.de>
Date: Sat, 10 Feb 2018 00:36:15 +0100
Subject: [PATCH] [TASK] Update UC in recycler only once per action

The UC of a backend user is now updated only once per request, if there
are actual changes.

Resolves: #83839
Releases: master, 8.7
Change-Id: I859f8b2cc94b6254251ecf639222201cbf57f1ad
Reviewed-on: https://review.typo3.org/55641
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Tested-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
---
 .../Controller/RecyclerAjaxController.php     | 21 +++++++++++--------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/typo3/sysext/recycler/Classes/Controller/RecyclerAjaxController.php b/typo3/sysext/recycler/Classes/Controller/RecyclerAjaxController.php
index c898ffd7548b..ea5c0616b7bc 100644
--- a/typo3/sysext/recycler/Classes/Controller/RecyclerAjaxController.php
+++ b/typo3/sysext/recycler/Classes/Controller/RecyclerAjaxController.php
@@ -75,16 +75,18 @@ class RecyclerAjaxController
         // Determine the scripts to execute
         switch ($this->conf['action']) {
             case 'getTables':
-                $this->setDataInSession('depthSelection', $this->conf['depth']);
+                $this->setDataInSession(['depthSelection' => $this->conf['depth']]);
 
                 /* @var $model Tables */
                 $model = GeneralUtility::makeInstance(Tables::class);
                 $content = $model->getTables($this->conf['startUid'], $this->conf['depth']);
                 break;
             case 'getDeletedRecords':
-                $this->setDataInSession('tableSelection', $this->conf['table']);
-                $this->setDataInSession('depthSelection', $this->conf['depth']);
-                $this->setDataInSession('resultLimit', $this->conf['limit']);
+                $this->setDataInSession([
+                    'tableSelection' => $this->conf['table'],
+                    'depthSelection' => $this->conf['depth'],
+                    'resultLimit' => $this->conf['limit'],
+                ]);
 
                 /* @var $model DeletedRecords */
                 $model = GeneralUtility::makeInstance(DeletedRecords::class);
@@ -154,14 +156,15 @@ class RecyclerAjaxController
     /**
      * Sets data in the session of the current backend user.
      *
-     * @param string $identifier The identifier to be used to set the data
-     * @param string $data The data to be stored in the session
+     * @param array $data The data to be stored in the session
      */
-    protected function setDataInSession($identifier, $data)
+    protected function setDataInSession(array $data)
     {
         $beUser = $this->getBackendUser();
-        $beUser->uc['tx_recycler'][$identifier] = $data;
-        $beUser->writeUC();
+        if (!empty(array_diff_assoc($data, $beUser->uc['tx_recycler']))) {
+            $beUser->uc['tx_recycler'] = array_merge($beUser->uc['tx_recycler'], $data);
+            $beUser->writeUC();
+        }
     }
 
     /**
-- 
GitLab