How to update multiple rows to not skills
Hi everyone. I need to import an Excel ~ 20k rows to update data stocks level. I'm using chunks (500) and loop to call query update tabel_name set column = ? Where id = ?. However, it was terminated by SIGKILL; not expected. How to update it become faster. My code: $stocks_level_mapped = []; // About 20k index
collect($stocks_level_mapped)->chunk(500)->each(function($divisions) { foreach($divisions->toArray() as $division) { $barcode = data_get($division, 'barcode'); $inventory = (int) data_get($division, 'on_hand'); \Log::debug("Start update stocks {$barcode}"); ProductVariantStock::where('barcode', data_get($division, 'barcode')) ->where('stock_id', (int) data_get($division, 'stock_id')) ->where('channel_id', (int) data_get($division, 'channel_id')) ->update(['on_hand' => (int) $inventory]); \Log::debug("End update stocks {$barcode} - number: {$inventory}"); } });
Thanks
Please or to participate in this conversation.