时间:2019-12-02来源:电脑系统城作者:电脑系统城
场景:
代码:
async batchUpdate(skus, { transaction }) {
const result = await Promise.all(skus.map(async sku => {
const record = await this.app.model.Sku.upsert(sku, { transaction });
return record;
}));
// SaaS 中删掉的 sku,插件也要同步删除
const ids = _.map(skus, 'sku_id');
const productIds = _.map(skus, 'product_id');
const { Op } = this.app.Sequelize;
await this.app.model.Sku.destroy({
where: {
sku_id: { [Op.notIn]: ids },
product_id: productIds,
}, transaction,
});
return result;
};
分析:
结论:
优化后代码:
async batchUpdate(skus, { transaction }) {
const result = await Promise.all(skus.map(async sku => {
const record = await this.app.model.Sku.upsert(sku, { transaction });
return record;
}));
// SaaS 中删掉的 sku,插件也要同步删除
const ids = _.map(skus, 'sku_id');
const productIds = _.map(skus, 'product_id');
const { Op } = this.app.Sequelize;
const delSkus = await this.app.model.Sku.findAll({
where: {
sku_id: { [Op.notIn]: ids },
product_id: productIds,
}, transaction,
});
if (delSkus && delSkus.length) {
await this.app.model.Sku.destroy({
where: {
sku_id: delSkus.map(sku => sku.sku_id),
}, transaction,
});
}
return result;
};
2023-03-15
SQLserver存储过程写法与设置定时执行存储过程方法详解2023-03-11
sql语句将数据库一条数据通过分隔符切割成多列方法实例2023-03-06
MySQL中的常用树形结构设计总结最详细的 SQLSERVER ALWAYSON配置教程 一、准备工作: 二、搭建故障转移群集 三、搭建数据库AlwaysOn 四、过程中可能遇到的问题...
2023-03-06
2.1破解的时候,先要断网,然后再操作,按如图打开界面,点击Manage License 2.2点击Activate 2.3打开SQL.Prompt.Keygen.exe,将生成的注册码拷贝到输入框内,然后点击Activate 2.4 继续点击Activate manually 2.5 按如下步骤操...
2023-03-06