Skip to content

Commit a2c390b

Browse files
committed
fix performance issues with cloud filesystem
1 parent 0f70d9b commit a2c390b

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

src/LfmItem.php

+10-12
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ class LfmItem
99
{
1010
private $lfm;
1111
private $helper;
12+
private $isDirectory;
13+
private $mimeType = null;
1214

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

16-
public function __construct(LfmPath $lfm, Lfm $helper)
18+
public function __construct(LfmPath $lfm, Lfm $helper, $isDirectory = false)
1719
{
1820
$this->lfm = $lfm->thumb(false);
1921
$this->helper = $helper;
22+
$this->isDirectory = $isDirectory;
2023
}
2124

2225
public function __get($var_name)
@@ -50,7 +53,7 @@ public function path($type = 'absolute')
5053

5154
public function isDirectory()
5255
{
53-
return $this->lfm->isDirectory();
56+
return $this->isDirectory;
5457
}
5558

5659
public function isFile()
@@ -66,11 +69,7 @@ public function isFile()
6669
*/
6770
public function isImage()
6871
{
69-
if (!$this->isDirectory()) {
70-
return Str::startsWith($this->mimeType(), 'image');
71-
}
72-
73-
return false;
72+
return $this->isFile() && Str::startsWith($this->mimeType(), 'image');
7473
}
7574

7675
/**
@@ -79,14 +78,13 @@ public function isImage()
7978
* @param mixed $file Real path of a file or instance of UploadedFile.
8079
* @return string
8180
*/
82-
// TODO: uploaded file
8381
public function mimeType()
8482
{
85-
// if ($file instanceof UploadedFile) {
86-
// return $file->getMimeType();
87-
// }
83+
if (is_null($this->mimeType)) {
84+
$this->mimeType = $this->lfm->mimeType();
85+
}
8886

89-
return $this->lfm->mimeType();
87+
return $this->mimeType;
9088
}
9189

9290
public function extension()

src/LfmPath.php

+5-9
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function path($type = 'storage')
7070
} elseif ($type == 'storage') {
7171
// storage: files/{user_slug}
7272
// storage on windows: files\{user_slug}
73-
return $this->translateToOsPath($this->path('url'));
73+
return str_replace(Lfm::DS, $this->helper->ds(), $this->path('url'));
7474
} else {
7575
// absolute: /var/www/html/project/storage/app/files/{user_slug}
7676
// absolute on windows: C:\project\storage\app\files\{user_slug}
@@ -83,11 +83,6 @@ public function translateToLfmPath($path)
8383
return str_replace($this->helper->ds(), Lfm::DS, $path);
8484
}
8585

86-
public function translateToOsPath($path)
87-
{
88-
return str_replace(Lfm::DS, $this->helper->ds(), $path);
89-
}
90-
9186
public function url()
9287
{
9388
return $this->storage->url($this->path('url'));
@@ -96,7 +91,7 @@ public function url()
9691
public function folders()
9792
{
9893
$all_folders = array_map(function ($directory_path) {
99-
return $this->pretty($directory_path);
94+
return $this->pretty($directory_path, true);
10095
}, $this->storage->directories());
10196

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

118-
public function pretty($item_path)
113+
public function pretty($item_path, $isDirectory = false)
119114
{
120115
return Container::getInstance()->makeWith(LfmItem::class, [
121116
'lfm' => (clone $this)->setName($this->helper->getNameFromPath($item_path)),
122-
'helper' => $this->helper
117+
'helper' => $this->helper,
118+
'isDirectory' => $isDirectory
123119
]);
124120
}
125121

0 commit comments

Comments
 (0)