[TASK] Remove static cache in StorageRepository 84/57684/2
authorChristian Kuhn <lolli@schwarzbu.ch>
Tue, 5 Jun 2018 23:12:07 +0000 (01:12 +0200)
committerAndreas Fernandez <a.fernandez@scripting-base.de>
Wed, 25 Jul 2018 19:36:38 +0000 (21:36 +0200)
Class StorageRepository parks static state in property
$storageRowCache. This is ugly and needs proper reset
functionality. However, the class is also a singleton through
AbstractRepository, so there is no need to make $storageRowCache
static in the first place. Just making the property non-static
keeps all the functionality, and removes the hard to
evict static state at the same time.

Resolves: #85647
Releases: master
Change-Id: I6c8dd489b05f80f2450e1d39051da5b8e53c55a0
Reviewed-on: https://review.typo3.org/57684
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
typo3/sysext/core/Classes/Resource/StorageRepository.php

index 403dae6..be9bdb3 100644 (file)
@@ -32,7 +32,7 @@ class StorageRepository extends AbstractRepository implements LoggerAwareInterfa
     /**
      * @var array|null
      */
-    protected static $storageRowCache;
+    protected $storageRowCache;
 
     /**
      * @var string
@@ -62,8 +62,8 @@ class StorageRepository extends AbstractRepository implements LoggerAwareInterfa
     public function findByUid($uid)
     {
         $this->initializeLocalCache();
-        if (isset(self::$storageRowCache[$uid])) {
-            return $this->factory->getStorageObject($uid, self::$storageRowCache[$uid]);
+        if (isset($this->storageRowCache[$uid])) {
+            return $this->factory->getStorageObject($uid, $this->storageRowCache[$uid]);
         }
         return null;
     }
@@ -73,7 +73,7 @@ class StorageRepository extends AbstractRepository implements LoggerAwareInterfa
      */
     protected function initializeLocalCache()
     {
-        if (static::$storageRowCache === null) {
+        if ($this->storageRowCache === null) {
             $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
                 ->getQueryBuilderForTable($this->table);
 
@@ -87,19 +87,19 @@ class StorageRepository extends AbstractRepository implements LoggerAwareInterfa
                 ->orderBy('name')
                 ->execute();
 
-            static::$storageRowCache = [];
+            $this->storageRowCache = [];
             while ($row = $result->fetch()) {
                 if (!empty($row['uid'])) {
-                    static::$storageRowCache[$row['uid']] = $row;
+                    $this->storageRowCache[$row['uid']] = $row;
                 }
             }
 
             // if no storage is created before or the user has not access to a storage
-            // static::$storageRowCache would have the value array()
+            // $this->storageRowCache would have the value array()
             // so check if there is any record. If no record is found, create the fileadmin/ storage
             // selecting just one row is enough
 
-            if (static::$storageRowCache === []) {
+            if ($this->storageRowCache === []) {
                 $connection = GeneralUtility::makeInstance(ConnectionPool::class)
                     ->getConnectionForTable($this->table);
 
@@ -114,7 +114,7 @@ class StorageRepository extends AbstractRepository implements LoggerAwareInterfa
                         true
                     ) > 0) {
                         // reset to null to force reloading of storages
-                        static::$storageRowCache = null;
+                        $this->storageRowCache = null;
                         // call self for initialize Cache
                         $this->initializeLocalCache();
                     }
@@ -137,7 +137,7 @@ class StorageRepository extends AbstractRepository implements LoggerAwareInterfa
         $driverRegistry = GeneralUtility::makeInstance(Driver\DriverRegistry::class);
 
         $storageObjects = [];
-        foreach (static::$storageRowCache as $storageRow) {
+        foreach ($this->storageRowCache as $storageRow) {
             if ($storageRow['driver'] !== $storageType) {
                 continue;
             }
@@ -167,7 +167,7 @@ class StorageRepository extends AbstractRepository implements LoggerAwareInterfa
         $driverRegistry = GeneralUtility::makeInstance(Driver\DriverRegistry::class);
 
         $storageObjects = [];
-        foreach (static::$storageRowCache as $storageRow) {
+        foreach ($this->storageRowCache as $storageRow) {
             if ($driverRegistry->driverExists($storageRow['driver'])) {
                 $storageObjects[] = $this->factory->getStorageObject($storageRow['uid'], $storageRow);
             } else {