From 4e201e44683b21cba20a6b0c6a1aa31170a4e8b3 Mon Sep 17 00:00:00 2001 From: limcross Date: Wed, 9 Nov 2022 00:41:35 -0300 Subject: [PATCH] perf: avoid to wait for tables if is not necessary --- src/_update_replication.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/_update_replication.js b/src/_update_replication.js index 80bc082..71e0863 100644 --- a/src/_update_replication.js +++ b/src/_update_replication.js @@ -67,13 +67,15 @@ module.exports = async (arc, stage, dryRun) => { ReplicaUpdates: [ replicateUpdate ] }).promise() - do { // Wait to avoid errors with busy tables - await new Promise(r => setTimeout(r, 5000)); - ({ Table } = await dynamoPrimary.describeTable({ TableName: PhysicalTableName }).promise()) - } while ( - !Table.Replicas || - Table.Replicas.findIndex((replica) => [ 'CREATING', 'UPDATING', 'DELETING' ].includes(replica.ReplicaStatus)) >= 0 - ) + if (replicateUpdates.length > 1) { + do { // Wait to avoid errors with busy table + await new Promise(r => setTimeout(r, 5000)); + ({ Table } = await dynamoPrimary.describeTable({ TableName: PhysicalTableName }).promise()) + } while ( + !Table.Replicas || + Table.Replicas.findIndex((replica) => [ 'CREATING', 'UPDATING', 'DELETING' ].includes(replica.ReplicaStatus)) >= 0 + ) + } } } catch (error) {