我正在运行自定义产品导入脚本(可配置的,具有额外属性,类别照片等的可配置的简单产品等(。
我将类别分配给新创建的产品时($类别包含类别ID的数组(
将类别分配给新创建的产品时,我正面临一个奇怪的"等待"。$categoryLinkRepository->assignProductToCategories($product->getSku(), $categories);
调查后,我发现延迟开始时脚本在以下功能中执行第二个循环的循环
public function assignProductToCategories($productSku, array $categoryIds)
{
$product = $this->getProductRepository()->get($productSku);
$assignedCategories = $this->getProductResource()->getCategoryIds($product);
foreach (array_diff($assignedCategories, $categoryIds) as $categoryId) {
$this->getCategoryLinkRepository()->deleteByIds($categoryId, $productSku);
}
foreach (array_diff($categoryIds, $assignedCategories) as $categoryId) {
/** @var MagentoCatalogApiDataCategoryProductLinkInterface $categoryProductLink */
$categoryProductLink = $this->productLinkFactory->create();
$categoryProductLink->setSku($productSku);
$categoryProductLink->setCategoryId($categoryId);
$categoryProductLink->setPosition(0);
$this->getCategoryLinkRepository()->save($categoryProductLink);
}
$productCategoryIndexer = $this->getIndexerRegistry()->get(IndexerProductCategory::INDEXER_ID);
if (!$productCategoryIndexer->isScheduled()) {
$productCategoryIndexer->reindexRow($product->getId());
}
return true;
}
奇怪的是,当我为现有产品运行它的运行良好时,同一功能仅针对新创建的产品延迟。
服务器上的mySQL进程显示重复查询等待66秒
Sending data CREATE TEMPORARY TABLE `tmp_select_tUFtPSHTf3LaHnv19OnapfygPIfXxdCU` (PRIMARY KEY(`url_rewrite_id`),
我只在生产服务器(运行MariaDB 10.3.16(而不是在我的本地开发VM(MySQL 5.7(
上面对此问题。我认为问题与服务器上的MySQL配置有关。任何想法都受到欢迎
我认为新产品保存会让您等待,因为它根据已分配给该产品的类别在url_rewrite中输入该产品