php - Magento 2 脚本等待创建临时表

标签 php mysql mariadb magento2

我正在运行自定义产品导入脚本(导入具有额外属性、类别照片等的可配置的简单产品)。

在使用($categories 包含类别 ID 数组)将类别分配给新创建的产品时,我在脚本执行时面临奇怪的“等待”

$categoryLinkRepository->assignProductToCategories($product->getSku(), $categories);

经过调查,我发现当脚本在以下函数中执行第二个for循环时,延迟开始

 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 \Magento\Catalog\Api\Data\CategoryProductLinkInterface $categoryProductLink */
        $categoryProductLink = $this->productLinkFactory->create();
        $categoryProductLink->setSku($productSku);
        $categoryProductLink->setCategoryId($categoryId);
        $categoryProductLink->setPosition(0);
        $this->getCategoryLinkRepository()->save($categoryProductLink);
    }
    $productCategoryIndexer = $this->getIndexerRegistry()->get(Indexer\Product\Category::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 中创建一个条目

关于php - Magento 2 脚本等待创建临时表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56924479/

相关文章:

php - mysql查询错误

php - Laravel Vapor 和 Lavavel Excel 排队导入失败。由于临时存储不存在 Laravel 8 Vapor

mysql - SQL Server 数据类型

SQL |搜索大字符串以返回表中找到的关键短语

python - 如何获取 django 模板来从两个不同的模型中提取信息?

php - 在 MAMP Pro 中安装 zip 扩展名

PHP 我怎么能回显这个 html?

mysql - MyISAM DB 可以存储多少数据?

python - Docker + Django + MySQL - 非 native 分区表列表末尾

mysql - 加载数据时 "ERROR 2013 (HY000): Lost connection to MySQL server during query"