Now let's start testing the performance of our search query, which is pretty complex and large.
First Postman Run with Big Data
For testing, I've used the seeder from the previous lesson a few times, with even bigger data, so currently I have:
- 300 000 properties
- 600 000 apartments (2 apartments per property)
- 1 200 000 bookings
And here's a reminder of what the Search Controller method looks like:...
First of all, exceptional course, Povilas! Literally way to go!
Just wanna share my suggestion for improving optimization, specifically in the moment below:
->when($request->price_to, function($query) use ($request) {... ->when($request->price_to, function($query) use ($request) {...
Basically there are two "similar" queries executed. So, you can just wrap into one:
->when($request->pricefrom || $request->priceto, function($query) use ($request) { $query->whereHas('apartments.prices', function($query) use ($request) { $query->when($request->priceto, function($query) use ($request) { $query->where('price', '<=', $request->priceto); }) ->when($request->pricefrom, function($query) use ($request) { $query->where('price', '>=', $request->pricefrom); }); }); })*
I didn`t test it but actually seems to have to work properly
Thanks for the kind words! Mmm, I like your suggestion, that would probably be faster indeed.