diff --git a/packages/node-core/src/db/db.module.ts b/packages/node-core/src/db/db.module.ts index 9f0ae38071..b3d8f0c447 100644 --- a/packages/node-core/src/db/db.module.ts +++ b/packages/node-core/src/db/db.module.ts @@ -66,7 +66,6 @@ const buildSequelizeOptions = (nodeConfig: NodeConfig, option: DbOption): Sequel dialect: 'postgres', ssl: nodeConfig.isPostgresSecureConnection, dialectOptions: { - options: {requestTimeout: nodeConfig.timeout * 1000}, // configure timeout is in seconds, requestTimeout is in milliseconds ssl: { rejectUnauthorized: false, ca: nodeConfig.postgresCACert, diff --git a/packages/node-core/src/indexer/poi/poi.service.ts b/packages/node-core/src/indexer/poi/poi.service.ts index 9ae584f7ff..3ea392f998 100644 --- a/packages/node-core/src/indexer/poi/poi.service.ts +++ b/packages/node-core/src/indexer/poi/poi.service.ts @@ -152,15 +152,6 @@ export class PoiService implements OnApplicationShutdown { } async rewind(targetBlockHeight: number, transaction: Transaction): Promise { - await this.poiRepo.model.destroy({ - transaction, - where: { - id: { - [Op.gt]: targetBlockHeight, - }, - }, - }); - await batchDeletePoi(this.poiRepo.model, transaction, targetBlockHeight); const lastSyncedPoiHeight = await this.storeCache.metadata.find('latestSyncedPoiHeight'); @@ -186,9 +177,8 @@ async function batchDeletePoi( model: PoiRepo, transaction: Transaction, targetBlockHeight: number, - batchSize = 10 + batchSize = 10000 ): Promise { - // const offset = 0; let completed = false; // eslint-disable-next-line no-constant-condition while (!completed) { diff --git a/packages/node-core/src/indexer/store.service.ts b/packages/node-core/src/indexer/store.service.ts index 0a69c8391a..6400555e05 100644 --- a/packages/node-core/src/indexer/store.service.ts +++ b/packages/node-core/src/indexer/store.service.ts @@ -900,23 +900,25 @@ async function batchDeleteAndThenUpdate( // eslint-disable-next-line no-constant-condition while (!completed) { try { - const recordsToUpdate = await model.findAll({ - transaction, - limit: batchSize, - attributes: {include: ['_id']}, - offset, // We need to apply offset, because after update the records, the record could still with in range, avoid endless query here. - where: { - __block_range: { - [Op.contains]: targetBlockHeight, + const [recordsToUpdate, recordsToDelete] = await Promise.all([ + model.findAll({ + transaction, + limit: batchSize, + attributes: {include: ['_id']}, + offset, // We need to apply offset, because after update the records, the record could still with in range, avoid endless query here. + where: { + __block_range: { + [Op.contains]: targetBlockHeight, + }, }, - }, - }); - const recordsToDelete = await model.findAll({ - transaction, - limit: batchSize, - attributes: {include: ['_id']}, - where: sequelize.where(sequelize.fn('lower', sequelize.col('_block_range')), Op.gt, targetBlockHeight), - }); + }), + model.findAll({ + transaction, + limit: batchSize, + attributes: {include: ['_id']}, + where: sequelize.where(sequelize.fn('lower', sequelize.col('_block_range')), Op.gt, targetBlockHeight), + }), + ]); if (recordsToDelete.length === 0 && recordsToUpdate.length === 0) { break; completed = true;