I'm trying to make an image gallery. For this purpose i'm storing the original images (right now about 7000 and in future there will be over 60.000) in the storage laravel path. Next i make a job that stores the path and metadata(image size, resolution, mimetype, width and height) to db.
The problem is its very very slow.
this is my controller:
public function startJob() {
// Start doing Jobs
CreateDirectories::withChain([
new RecordPaths,
// new OptimizeImage,
// new SendNotification,
])->dispatch()->delay(now()->addSeconds(3));
echo 'create directories and stored paths to database!';
}
In my controller i make some jobs. First it will make a directory where i'm storing thumbs. After this job is done the next one is RecordPaths to the DB.
And here is the problem it is very slow (image/2sec).
this is my job:
class RecordPaths implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function handle()
{
$this->truncate();
$files = Storage::disk('gallery')->allFiles();
foreach($files as $file) {
$thumb = new Thumb;
$thumb->brand = explode("/", $file, 2)[0];
$thumb->name = array_slice(explode("/", $file),-1)[0];
$thumb->path = $file;
//
$thumb->size = $this->imageMetadata($file, 'fileSize');
$thumb->width = $this->imageMetadata($file, 'imageWidth');
$thumb->height = $this->imageMetadata($file, 'imageHeight');
$thumb->mime = $this->imageMetadata($file, 'mimeType');
//
$thumb->save();
}
}
public function truncate() {
return Thumb::truncate();
}
public function imageMetadata($file, $type) {
$metaData = [];
$metaData['mimeType'] = \Image::make(storage_path("app\public\gallery\\") . $file)->exif('MimeType');
$metaData['fileSize'] = \Image::make(storage_path("app\public\gallery\\") . $file)->exif('FileSize');
$metaData['imageWidth'] = \Image::make(storage_path("app\public\gallery\\") . $file)->exif('ExifImageWidth');
$metaData['imageHeight'] = \Image::make(storage_path("app\public\gallery\\") . $file)->exif('ExifImageLength');
return $metaData[$type];
}
}
the $files = Storage::disk('gallery')->allFiles(); in the handle method return this: 
Do have anybody any idea how to speed it up ?
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2x8jc62
via IFTTT

Aucun commentaire:
Enregistrer un commentaire