Skip to content

Commit

Permalink
fix(migrations): filter batches after promise is resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel910 committed Apr 30, 2024
1 parent 4753668 commit 90f428f
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions packages/migrations/src/migrations/5.40.0/001/ddb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,31 +100,33 @@ export class PbUniqueBlockElementIds_5_40_0_001 implements DataMigration {
);

const items = await Promise.all(
blocks
.map(async block => {
const newContent = await this.generateElementIds(block);
if (!newContent) {
return null;
}

return this.blockEntity.putBatch({
...block,
content: newContent
});
})
.filter(Boolean) as Promise<BatchWriteItem>[]
blocks.map(async block => {
const newContent = await this.generateElementIds(block);
if (!newContent) {
return null;
}

return this.blockEntity.putBatch({
...block,
content: newContent
});
})
);

const execute = () => {
return batchWriteAll({ table: this.blockEntity.table, items });
return batchWriteAll({
table: this.blockEntity.table,
items: items.filter(Boolean) as BatchWriteItem[]
});
};

await executeWithRetry(execute, {
onFailedAttempt: error => {
logger.error(
`"batchWriteAll" attempt #${error.attemptNumber} failed.`
);
logger.error(error.message);
console.log(items);
console.log(error);
}
});

Expand Down

0 comments on commit 90f428f

Please sign in to comment.