From 0a6dec433c535b13fcece43dab46e88e2f0be2f6 Mon Sep 17 00:00:00 2001 From: Christian Kuhn <lolli@schwarzbu.ch> Date: Wed, 6 Jun 2018 01:12:07 +0200 Subject: [PATCH] [TASK] Remove static cache in StorageRepository 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> --- .../Classes/Resource/StorageRepository.php | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/typo3/sysext/core/Classes/Resource/StorageRepository.php b/typo3/sysext/core/Classes/Resource/StorageRepository.php index 403dae6b7c62..be9bdb3db8e8 100644 --- a/typo3/sysext/core/Classes/Resource/StorageRepository.php +++ b/typo3/sysext/core/Classes/Resource/StorageRepository.php @@ -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 { -- GitLab