99 words, 1 min read
β οΈ This post links to an external website. β οΈ
In this episode, Harris from Laravel News tackles the issue of excessive queries in a test environment. The focus is on optimizing the top customers method, which previously generated hundreds of n+1 queries.
- Ensuring relationships are loaded before accessing them to avoid n+1 query problems.
- Creating a lookup table to avoid repeated query executions.
- Adding database indexes to improve query efficiency.
- Reducing the number of queries from 400 to 4.
- Cutting query execution time from 187 milliseconds to 40 milliseconds.
- Highlighting the importance of leveraging database optimizations over PHP calculations.
- Preparing to explore further optimizations in the next episode.
continue reading on www.youtube.com
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.