Skip to content

Commit

Permalink
Refactor code to improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Maksold committed Jul 11, 2024
1 parent 0f32f5a commit 2441a1a
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions Command/CatalogAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ protected function getFilePaths($useCache = true)
if ($useCache && $this->filePaths) {
return $this->filePaths;
}
if ($this->driverFile->isExists($this->getMediaDirectoryPath())) {
$this->filePaths = $this->driverFile->readDirectoryRecursively($this->getMediaDirectoryPath());
$cacheFiles = $this->getCacheFilePaths();
$this->filePaths = array_diff($this->filePaths, $cacheFiles);
//remove anything that's a directory
foreach ($this->filePaths as $k => $filePath) {
if ($this->driverFile->isDirectory($filePath)) {
unset($this->filePaths[$k]);
}
$mediaDirectoryPath = $this->getMediaDirectoryPath();
if (!$this->driverFile->isExists($mediaDirectoryPath)) {
return [];
}
$cacheFiles = $this->getCacheFilePaths();
$this->filePaths = [];
foreach ($this->driverFile->readDirectoryRecursively($mediaDirectoryPath) as $filePath) {
if (!in_array($filePath, $cacheFiles, true) && !$this->driverFile->isDirectory($filePath)) {
$this->filePaths[] = $filePath;
}
}
return $this->filePaths;
Expand Down Expand Up @@ -226,13 +226,12 @@ protected function getCacheFilePaths($useCache = true)
return $this->cacheFilePaths;
}
if ($this->driverFile->isExists($this->getCacheDirectoryPath())) {
$this->cacheFilePaths = $this->driverFile->readDirectoryRecursively($this->getCacheDirectoryPath());
//remove anything that's a directory
foreach ($this->cacheFilePaths as $k => $cacheFilePath) {
if ($this->driverFile->isDirectory($cacheFilePath)) {
unset($this->cacheFilePaths[$k]);
$this->cacheFilePaths = array_filter(
$this->driverFile->readDirectoryRecursively($this->getCacheDirectoryPath()),
function ($filePath) {
return !$this->driverFile->isDirectory($filePath); // skip directories
}
}
);
}
return $this->cacheFilePaths;
}
Expand Down

0 comments on commit 2441a1a

Please sign in to comment.