From 9e34cb295ec240b44db97639a34c427ce1754f77 Mon Sep 17 00:00:00 2001 From: Adrien Foulon <6115458+Tofandel@users.noreply.github.com> Date: Thu, 17 Nov 2022 16:42:12 +0100 Subject: [PATCH] [Micro Optimization] Use slice instead of reverse->take (#3098) This does exactly the same but avoiding an array reverse --- src/MediaCollections/FileAdder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MediaCollections/FileAdder.php b/src/MediaCollections/FileAdder.php index f9ed0a9ed..8e348a7a3 100644 --- a/src/MediaCollections/FileAdder.php +++ b/src/MediaCollections/FileAdder.php @@ -471,7 +471,7 @@ protected function processMediaItem(HasMedia $model, Media $media, self $fileAdd $collectionMedia = $this->subject->fresh()->getMedia($media->collection_name); if ($collectionMedia->count() > $collectionSizeLimit) { - $model->clearMediaCollectionExcept($media->collection_name, $collectionMedia->reverse()->take($collectionSizeLimit)); + $model->clearMediaCollectionExcept($media->collection_name, $collectionMedia->slice(-$collectionSizeLimit, $collectionSizeLimit)); } } }