Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Optimizing Search Endpoint

Premium
17 min read

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:...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (29 h 14 min)

You also get:

54 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

AM
Anton Mykhailovskyi ✓ Link copied!

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

PK
Povilas Korop ✓ Link copied!

Thanks for the kind words! Mmm, I like your suggestion, that would probably be faster indeed.

DS
Dmytro Sakharuk ✓ Link copied!

Thank you, this and the previous lesson are very interesting.