StackByte - Using chunking and cursors in Laravel to reduce query memory usage.
Вставка
- Опубліковано 2 лют 2025
- Working with thousands of record in Laravel is pretty easy - you don't really have to change how you do things, you can just keep on using Eloquent to query data.
BUT there might come a time where your record sets are in hundreds of thousands, and querying them or making bulk reads, writes or updates might cause a few problems - like running out of memory or running out of execution time.
Did this video help you? Buy me a coffee here:
www.buymeacoff...
Here, we look at a sample Laravel app seeded with 300,000 user records and try various ways of iterating over them all.
Laravel DebugBar - github.com/bar...
Wikipedia, Data base Cursors - en.wikipedia.o...
Very well done, beautifully explained!
Dude! This is what i needed! Well explained !
The ending had me dead, 'so there we are, we haven't yet blown up the server, don't forget to subscribe!' xD
Sir, How to implement batch deletion in JPA repository using cursor approach??
cursor or chunk which is better to use (taking account of memory and time)
It's a balancing act - cursor may put more weight on your database server, whereas chunk shunts the responsibility to loading a number of records in memory in PHP. If you have an application for either, I tend to use chunk first out of habit, then if that's not going so well, try cursor.