Very very slow to speed up

Posted 1 year ago by deansatch

I have this:

        $subQuery = function($q)use($start, $end){
                       $q->whereHas('classdates', function($q)use( $start, $end){
                            $q->whereBetween('datetime',[ $start, $end]);

        $subQuery2 = function($q)use($start, $end){
                        $q->whereHas('classes.classdates', function($q)use( $start, $end){
                            $q->whereBetween('datetime',[ $start, $end]);
        $studios = \App\Studio::
        withCount(['classes' => $subQuery])
        ->withCount(['bookings' => $subQuery2])

It takes about 20 seconds to run just for a one month date range and I need it to run for full years or even more.

Is there a way I could speed this up?

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.