数据库
首页 > 数据库> > 数据库死锁的问题,Deadlock found when trying to get lock; try restarting transaction at Query.formatError

数据库死锁的问题,Deadlock found when trying to get lock; try restarting transaction at Query.formatError

作者:互联网

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;
  };

标签:sku,transaction,const,app,try,死锁,trying,id,skus
来源: https://www.cnblogs.com/xulonglong/p/shu-ju-ku-si-suo-de-wen-tideadlock-found-when-tryi.ht