chunk(), lazy() и cursor() в Laravel: замеры памяти и почему chunk() теряет половину строк при обновлении
A Laravel article examines chunk(), lazy() and cursor() for processing large tables. It says the common advice to avoid all() and use chunk() is correct but incomplete. chunk() has a trap that can cause a background job to silently process only part of the rows. The article includes memory measurements for five ways to traverse a 100,000-row table, analyzes the lost rows and sets out rules for choosing a method.
Когда в Laravel нужно обработать большую таблицу, обычно советуют «не делать all(), использовать chunk()». Совет верный, но неполный: у chunk() есть ловушка, из-за которой фоновая задача тихо обрабатывает только часть строк. Ниже замеры пяти способов обхода таблицы на 100 000 строк, разбор потери строк и правила выбора метода. Читать далее