php - 改进 CSV 产品导入 -> Array Category Query by name
问题描述
最近我们做了一个很大的改变,比如为我们的网站建立一个新的类别树,并将超过 200 万个产品移动到正确的类别中。
我们没有性能问题,一切运行顺利。
我唯一的问题是,现在类别树更加复杂和深入,并且在通过 CSV 导入添加新文章时会受到影响(超时脚本,非常慢,脚本崩溃)基本上是通过 CSV 添加新产品时类别字段始终为文本(由“#”分隔)示例:Engine#Crankshaft#Audi#Audi A5
那么问题出在我的获取categoryID的函数中,以防数据库中已经存在或不存在。我该如何改进?我认为主要问题在于创建的非常大的数组
protected function _getCategoriesID($field_value)
{
global $Database;
$products_categories = array();
$separator = $this->_getSeparator($field_value);
$category_array = array();
if ($separator != '') {
$category_array = explode($separator, $field_value);
$category_array = array_reverse($category_array);
} else {
$category_array[0] = $field_value;
}
unset($separator);
$Qcategory = $Database->query('select c0.categories_id from :table_categories as c0 inner join :table_categories_description as cd on c0.categories_id=cd.categories_id where cd.categories_name = :categories_name and cd.language_id=:language_id');
$Qcategory->bindTable(':table_categories', TABLE_CATEGORIES);
$Qcategory->bindTable(':table_categories_description', TABLE_CATEGORIES_DESCRIPTION);
$Qcategory->bindValue(':categories_name', $category_array[0]);
$Qcategory->bindInt(':language_id', $this->language);
$count = 1;
if (count($category_array) > 1) {
while ($count < count($category_array)) {
$Qcategory->appendQuery(' and c' . ($count - 1) . '.parent_id in (select c' . $count . '.categories_id from :table_categories' . $count . ' as c' . $count . ' inner join :table_categories_description' . $count . ' as cd' . $count . ' on c' . $count . '.categories_id=cd' . $count . '.categories_id where cd' . $count . '.categories_name = :categories_name' . $count . ' and cd' . $count . '.language_id=:language_id' . $count . ' ');
$Qcategory->bindTable(':table_categories' . $count, TABLE_CATEGORIES);
$Qcategory->bindTable(':table_categories_description' . $count, TABLE_CATEGORIES_DESCRIPTION);
$Qcategory->bindValue(':categories_name' . $count, $category_array[$count]);
$Qcategory->bindInt(':language_id' . $count, $this->language);
$count++;
}
for ($i = 0; $i < $count - 1; $i++) {
$Qcategory->appendQuery(')');
}
}
$Qcategory->execute();
while ($Qcategory->next()) {
$products_categories[] = $Qcategory->value('categories_id');
}
unset($Qcategories);
return $products_categories;
}
解决方案
推荐阅读
- javascript - 使用 JQuery 计算 html 中具有相似前缀的数据属性
- javascript - Laravel Livewire 电线:点击不触发
- python - 如何为线性回归重塑数据
- python-3.x - Python:在 Google Colab 中使用 Selenium 自动将数据输入到 Google Drive
- java - Apache NIFI 自定义处理器给出错误“找不到合适的驱动程序”
- python - 从python的fasta文件之间找到主题
- hybris - 当我在 Hybris 中本地化枚举类型时,如何解决 java.lang.IllegalStateException?
- python - 解码ASCII时,是否应该故意省略奇偶校验位?
- class - UML 类图中信号的正确设计是什么?
- xcode - UICollectionView 的单元格中的按钮不起作用