I have around ~10k of products to create programmatically. I also have around 20 custom attributes. Saving the stock, the price, special price, those 20 custom attributes it takes around < 50 min. Once I added the image part, from 50 mins its jumps to 8 hours. The images are big indeed, but 8 hours its a lot of time.
This is my script of saving the images :
//$productData contains the attributes, prices, etc
$product = $this->productInterfaceFactory->create(['data' => $productData]);
$product = $this->productRepository->save($product);
$images = $this->getImages(); // its an array contains the image path
if (count($images) > 0) {
for ($i = 0; $i < count($images); $i++) {
if ($i === 0) {
$product->addImageToMediaGallery($images[$i], ['image', 'small_image', 'thumbnail'], false, false);
} else {
$product->addImageToMediaGallery($images[$i], ['image'], false, false);
}
$product->save();
}
}
Is there a way to reduce the execution time? I was thinking to keep saving the products and the attributes in one cronjob and the images to put into another cronjob, but I am opened to other suggestions as well. Please advice.
Thank you