D
D
demeys2019-04-28 16:25:10
Laravel
demeys, 2019-04-28 16:25:10

How to reduce the number of requests when displaying thumbnails in laravel-medialibrary?

Hey! I use spatie/laravel-medialibrary to load and modify images.
I like this package, but I ran into a little performance problem.
I'm under the impression that for each rendered media image, an additional DB query is executed, querying all the columns from the parent model element.
5cc5a90c1d6c0468481934.png
when outputting, I use
TeamsController.php

$items = Team::latest()->with("media")->limit(10)->get();

blade
@foreach ($items as $item)
                <img src="{{ $item->getFirstMediaURL('default', 'thumb') }}" />
            @endforeach

How to remove these additional queries to the database?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex Wells, 2019-04-29
@Alex_Wells

You obviously don't show us everything. I suppose that somewhere there is foreach($teams as $team), inside which foreach($team->media as $media), and from the media you do $media->team, which cause requests.
Throw off the entire code - the entire template, the controller, as well as the getFirstMediaURL method.

D
demeys, 2019-04-29
@demeys

found a problem.
It was in the CustomPathGenerator file when the path was formed
and additional requests were made

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question