Skip to content

Commit

Permalink
fix performance issues with cloud filesystem
Browse files Browse the repository at this point in the history
  • Loading branch information
streamtw committed May 10, 2020
1 parent 0f70d9b commit a2c390b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
22 changes: 10 additions & 12 deletions src/LfmItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ class LfmItem
{
private $lfm;
private $helper;
private $isDirectory;
private $mimeType = null;

private $columns = ['name', 'url', 'time', 'icon', 'is_file', 'is_image', 'thumb_url'];
public $attributes = [];

public function __construct(LfmPath $lfm, Lfm $helper)
public function __construct(LfmPath $lfm, Lfm $helper, $isDirectory = false)
{
$this->lfm = $lfm->thumb(false);
$this->helper = $helper;
$this->isDirectory = $isDirectory;
}

public function __get($var_name)
Expand Down Expand Up @@ -50,7 +53,7 @@ public function path($type = 'absolute')

public function isDirectory()
{
return $this->lfm->isDirectory();
return $this->isDirectory;
}

public function isFile()
Expand All @@ -66,11 +69,7 @@ public function isFile()
*/
public function isImage()
{
if (!$this->isDirectory()) {
return Str::startsWith($this->mimeType(), 'image');
}

return false;
return $this->isFile() && Str::startsWith($this->mimeType(), 'image');
}

/**
Expand All @@ -79,14 +78,13 @@ public function isImage()
* @param mixed $file Real path of a file or instance of UploadedFile.
* @return string
*/
// TODO: uploaded file
public function mimeType()
{
// if ($file instanceof UploadedFile) {
// return $file->getMimeType();
// }
if (is_null($this->mimeType)) {
$this->mimeType = $this->lfm->mimeType();
}

return $this->lfm->mimeType();
return $this->mimeType;
}

public function extension()
Expand Down
14 changes: 5 additions & 9 deletions src/LfmPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function path($type = 'storage')
} elseif ($type == 'storage') {
// storage: files/{user_slug}
// storage on windows: files\{user_slug}
return $this->translateToOsPath($this->path('url'));
return str_replace(Lfm::DS, $this->helper->ds(), $this->path('url'));
} else {
// absolute: /var/www/html/project/storage/app/files/{user_slug}
// absolute on windows: C:\project\storage\app\files\{user_slug}
Expand All @@ -83,11 +83,6 @@ public function translateToLfmPath($path)
return str_replace($this->helper->ds(), Lfm::DS, $path);
}

public function translateToOsPath($path)
{
return str_replace(Lfm::DS, $this->helper->ds(), $path);
}

public function url()
{
return $this->storage->url($this->path('url'));
Expand All @@ -96,7 +91,7 @@ public function url()
public function folders()
{
$all_folders = array_map(function ($directory_path) {
return $this->pretty($directory_path);
return $this->pretty($directory_path, true);
}, $this->storage->directories());

$folders = array_filter($all_folders, function ($directory) {
Expand All @@ -115,11 +110,12 @@ public function files()
return $this->sortByColumn($files);
}

public function pretty($item_path)
public function pretty($item_path, $isDirectory = false)
{
return Container::getInstance()->makeWith(LfmItem::class, [
'lfm' => (clone $this)->setName($this->helper->getNameFromPath($item_path)),
'helper' => $this->helper
'helper' => $this->helper,
'isDirectory' => $isDirectory
]);
}

Expand Down

0 comments on commit a2c390b

Please sign in to comment.