diff --git a/CHANGELOG.md b/CHANGELOG.md index 25dbfbca3..8a109f973 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All Notable changes to `laravel-medialibrary` will be documented in this file +##3.2.3 +- Add index to morphable fields in migration which could improve performance. +- Remove unnecessary query when adding a file + ##3.2.2 - Fixes tests diff --git a/resources/migrations/create_media_table.php.stub b/resources/migrations/create_media_table.php.stub index 9c2016b38..15a3ce030 100644 --- a/resources/migrations/create_media_table.php.stub +++ b/resources/migrations/create_media_table.php.stub @@ -13,9 +13,7 @@ class CreateMediaTable extends Migration { Schema::create('media', function (Blueprint $table) { $table->increments('id'); - $table->unsignedInteger('model_id')->nullable(); - $table->string('model_type')->nullable(); - $table->index(['model_id', 'model_type']); + $table->morphs('model'); $table->string('collection_name'); $table->string('name'); $table->string('file_name'); diff --git a/src/FileAdder/FileAdder.php b/src/FileAdder/FileAdder.php index 14580dc45..ab49abcf6 100644 --- a/src/FileAdder/FileAdder.php +++ b/src/FileAdder/FileAdder.php @@ -267,9 +267,8 @@ public function toCollectionOnDisk($collectionName = 'default', $diskName = '') $media->custom_properties = $this->customProperties; $media->manipulations = []; - $media->save(); - $this->subject->media()->save($media); + $this->fileSystem->add($this->pathToFile, $media, $this->fileName); if (!$this->preserveOriginal) {