Okay, I didn't think this through. It's not the hasManyThrough() method, it is Eloquent itself. I have about 2500 results from total of 360 000 records. I have indexes for the fields I need, the query is executing for about 100-200ms on Windows. I think the problem is when Eloquent builds the collections... anyone had this problem before ?
I think this works like eager loading... and I have written that doing big WHEREIN queries is bad practice. But I am not sure, I am not an expert, I have just read it in different websites... And some friend told me the same. May be you should use JOIN, Model::.....->join()->
Thanks, but I already tried Model::join()->..... and it's the same result. Guess the query builder works the same way. And if someone can provide an alternative to big whereIn() queries I'll be glad to hear it :)
I found a solution. Don't know if it's the best. I used simple DB::table() with joins to do the trick.
Just wondering what kind of objects did you get back? Was it collection with arrays or correspondig model instances?
Thanks.
No guessing if this is applicable or obvious, but are you guys using ->take(30)
, ->skip(30)
, ->paginate(30)
, or ->chunk(30,function($models){...}())
on any of your hard queries?
I have used chunk for a few queries where I had north of 30k results with each having more than 20 fields with strings, texts etc...
Paginate employs take() & skip() both !1
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community