Skip to content

Commit 712d6bd

Browse files
authored
Merge pull request #31 from aptudock/improve-performance
Major performance improvement for shops with many images and fast volumes
2 parents ffc1b1a + aa694ed commit 712d6bd

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Console/Command/RemoveUnusedMediaCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ public function execute(InputInterface $input, OutputInterface $output): int
165165
$imagesToKeep = $connection->fetchCol($select);
166166
}
167167

168+
$imagesToKeep = array_flip($imagesToKeep);
169+
168170
foreach (new RecursiveIteratorIterator($directoryIterator) as $file) {
169171
// Directory guard
170172
if ($this->driver->isDirectory($file)) {
@@ -188,7 +190,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
188190
}
189191

190192
$filePathWithoutCacheDir = preg_replace('#/cache_*/[a-z0-9]+(/[a-z0-9]/[a-z0-9]/.+?)#i', '$1', $filePath);
191-
if (in_array($filePathWithoutCacheDir, $imagesToKeep, true)) {
193+
if (array_key_exists($filePathWithoutCacheDir, $imagesToKeep)) {
192194
continue;
193195
}
194196

@@ -197,7 +199,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
197199
continue;
198200
}
199201

200-
if (in_array($filePath, $imagesToKeep, true)) {
202+
if (array_key_exists($filePath, $imagesToKeep)) {
201203
continue;
202204
}
203205

0 commit comments

Comments
 (0)