stefr
1 year ago

Time consuming script

Posted 1 year ago by stefr

I need to convert the timestamps from a table with about 500.000 records to a different timezone.

Because of this huge amount of records this script takes up too much time so a time-out is the result. I've never dealt with something like this before. I appreciate any good tips on how to take care of this.

        \App\Models\Visits::chunk(200, function ($items) {
            foreach ($items as $item) {
                $item->update([
                    'created_at' => \Timezone::convertToUTC($item->created_at, 'Europe/Amsterdam'),
                    'updated_at' => \Timezone::convertToUTC($item->updated_at, 'Europe/Amsterdam'),
                ]);
            }
        });

Please sign in or create an account to participate in this conversation.