From 66e128b3171413c0a8f4d8b1e126c27d79ce5d6b Mon Sep 17 00:00:00 2001 From: freek Date: Sun, 26 Jul 2015 11:13:57 +0200 Subject: [PATCH] avoid extra sql queries --- src/Conversion/ConversionCollection.php | 27 +++++++++++++------------ 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/Conversion/ConversionCollection.php b/src/Conversion/ConversionCollection.php index f660d5fd1..d21418032 100644 --- a/src/Conversion/ConversionCollection.php +++ b/src/Conversion/ConversionCollection.php @@ -55,21 +55,22 @@ public function getByName($name) */ protected function addConversionsFromRelatedModel(Media $media) { - static $cachedRegistrations = []; - - $cacheKey = $media->model_type; - - if (! isset($cachedRegistrations[$cacheKey])) { - - $cachedRegistrations[$cacheKey] = []; - - if ($media->model instanceof HasMedia) { - $media->model->registerMediaConversions(); - $cachedRegistrations[$cacheKey] = $media->model->mediaConversions; - } + $modelName = $media->model_type; + + /* + * To prevent an sql query create a new model instead + * of the using the associated one + */ + $model = new $modelName(); + + if ($model instanceof HasMedia) { + /* + * TODO: make this method static in the next version + */ + $model->registerMediaConversions(); } - $this->items = $cachedRegistrations[$cacheKey]; + $this->items = $model->mediaConversions; } /**