desperate for help: laravel eloquent queries slow after update, needs urgent performance optimization advice!
the core problem is specifically with eloquent relationships and some of our more complex queries. for example, pulling up a product page with its variants and associated data now takes like 5-10 seconds per request, which is just insane. before the update, these were milliseconds. its killing our app's responsiveness and i'm really struggling to find good eloquent performance optimization strategies that actually help.
i've tried a few things already, like checking the laravel debugbar (which clearly shows certain queries taking ages), i've added basic indexing on some foreign keys, and even reviewed recent code changes for obvious regressions. but seriously, nothing seems to fix this. it feels like the upgrade itself broke something fundamental in how eloquent handles these complex operations.
here's a dummy example from debugbar, showing how ridiculous the times are now:
[ 'query' => 'select * from "products" where "products"."id" = ? limit 1', 'time' => '0.05ms' ],
[ 'query' => 'select * from "variants" where "variants"."product_id" in (?)', 'time' => '4870.23ms' ],
[ 'query' => 'select * from "product_images" where "product_images"."variant_id" in (?)', 'time' => '2100.15ms' ],
// ... other queries
i'm really looking for some practical advice, common pitfalls after a laravel upgrade like this, or even advanced techniques for optimizing slow eloquent queries beyond just basic indexing. anything that could point me in the right direction would be a lifesaver. i'm kinda at my wit's end.
thanks in advance!
2 Answers
Charlotte Miller
Answered 5 hours agoHey Mei Park, an 'absol crawl' sounds like something out of a horror movie, and for app performance, it practically is! Those debugbar times strongly point to an N+1 query issue; ensure you're eagerly loading relationships like .with('variants.productImages') and using .select() for better database optimization. Did you confirm if eager loading these specific relationships is fully implemented?
Mei Park
Answered 2 hours agoOh nice! Eager loading totally fixed the N+1 issue, thanks so much Charlotte. But now I'm seeing some really strange cache invalidation problems with Redis after the upgrade, especially with product data. If anyone's got thoughts on that too, I'm all ears!