Replies: 1 comment
-
I agree that this should be optimised. Feel free to send a PR for this if you need this quickly. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
So I'm creating an excel importer for my table
Deals
...Each
Deals
has ManyPhotoset
and each
Photoset
has 3 media items associated with it... each media is under a single-file collection...I'm currently using Azure-Blob-Storage for storing this images and is using the package
matthewbdaly/laravel-azure-storage
which is just a standard filesystem adapter forleague/flysystem-azure-blob-storage
on my
Azure
Disk the all of the media-files already exists, all I need is to associate them into each photoset...to do this I have this code...
$deals
is all the deals, and$photosets
is an array of...the
handlePhoto
method isSo now I know what you're thinking... it's slow because media-library still needs to copy the image to a new folder...
but it doesn't really have to...
here's why, I create a custom
PathGenerator
just for the photosets model... this is the new path structure...example output would be
Photoset/original/1/randomname.png
, I know you're probably concerned that there will be 2 media file in one directory.. but that's not the case, because as I've said, each media in aphotoset
is under a single-file collection.here's the main problem...
as soon as
handlePhoto
is run it takes way too long to finish for each media... why? I don't really know... 😅I did a little digging into the codebase and found that the code that handles this is on the method
toMediaCollectionFromRemote
under the
/spatie/laravel-medialibrary/src/MediaCollections/FileAdder.php
Class...and I have check the steps it runs...
each of those steps require a back-and-forth communication with azure which I assume is very resource consuming.
then after instantiating the media object, it then attach it to the model...
where
copyToMediaLibraryFromRemote
method is going to handle themoving
of the file to thedestination
...found on
spatie/laravel-medialibrary/src/MediaCollections/Filesystem.php
which is also another request to azure... and this method also show even more requests to azure....
it should not move the file anymore or copy it because it already exists in the same directory as where it wants it to be...
Beta Was this translation helpful? Give feedback.
All reactions