diff --git a/packages/node-core/src/indexer/store.service.ts b/packages/node-core/src/indexer/store.service.ts index 9b99cac04c..149b3e5e38 100644 --- a/packages/node-core/src/indexer/store.service.ts +++ b/packages/node-core/src/indexer/store.service.ts @@ -292,17 +292,6 @@ export class StoreService { item.__block_range = [this.blockHeight, null]; }); }); - - sequelizeModel.addHook('beforeBulkDestroy', (instance) => { - instance.where = { - ...instance.where, - [Op.and]: this.sequelize.where( - this.sequelize.fn('lower', this.sequelize.col('_block_range')), - Op.eq, - this.blockHeight - ), - }; - }); } // TODO, remove id and block_range constraint, check id manually // see https://github.com/subquery/subql/issues/1542 diff --git a/packages/node-core/src/indexer/storeModelProvider/model/model.ts b/packages/node-core/src/indexer/storeModelProvider/model/model.ts index fc68c0f395..277d6acf8e 100644 --- a/packages/node-core/src/indexer/storeModelProvider/model/model.ts +++ b/packages/node-core/src/indexer/storeModelProvider/model/model.ts @@ -107,30 +107,28 @@ export class PlainModel implements IModel throw new Error(`Currently not supported: update by fields`); } - // Batch insert every 10000 data - const batchSize = 10000; - for (let i = 0; i < data.length; i += batchSize) { - const batchDatas = data.slice(i, i + batchSize); - - if (!this.historical) { - await this._bulkCreate(batchDatas, tx); - continue; - } - - await this.model.destroy({ - where: { - id: batchDatas.map((v) => v.id), - } as any, - limit: batchSize, - transaction: tx, - }); - await this.markAsDeleted( - batchDatas.map((v) => v.id), - blockHeight, - tx - ); - await this._bulkCreate(batchDatas, tx); + if (!this.historical) { + await this._bulkCreate(data, tx); + return; } + + await this.model.destroy({ + where: { + id: data.map((v) => v.id), + [Op.and]: this.sequelize.where( + this.sequelize.fn('lower', this.sequelize.col('_block_range')), + Op.eq, + blockHeight + ), + } as any, + transaction: tx, + }); + await this.markAsDeleted( + data.map((v) => v.id), + blockHeight, + tx + ); + await this._bulkCreate(data, tx); } async bulkRemove(ids: string[], blockHeight: number, tx?: Transaction): Promise {