Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jiqiang90 committed Oct 30, 2023
1 parent db62340 commit 382b09e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 28 deletions.
1 change: 0 additions & 1 deletion packages/node-core/src/db/db.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 1 addition & 11 deletions packages/node-core/src/indexer/poi/poi.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,6 @@ export class PoiService implements OnApplicationShutdown {
}

async rewind(targetBlockHeight: number, transaction: Transaction): Promise<void> {
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');

Expand All @@ -186,9 +177,8 @@ async function batchDeletePoi(
model: PoiRepo,
transaction: Transaction,
targetBlockHeight: number,
batchSize = 10
batchSize = 10000
): Promise<void> {
// const offset = 0;
let completed = false;
// eslint-disable-next-line no-constant-condition
while (!completed) {
Expand Down
34 changes: 18 additions & 16 deletions packages/node-core/src/indexer/store.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 382b09e

Please sign in to comment.