diff --git a/src/modules/repository/implementation/sequelize/repositories/shard-repository.js b/src/modules/repository/implementation/sequelize/repositories/shard-repository.js index d2a00d74e2..08dc04df82 100644 --- a/src/modules/repository/implementation/sequelize/repositories/shard-repository.js +++ b/src/modules/repository/implementation/sequelize/repositories/shard-repository.js @@ -108,7 +108,7 @@ class ShardRepository { } async updatePeerRecordLastDialed(peerId, timestamp) { - await this.model.update( + return this.model.update( { lastDialed: timestamp, }, @@ -119,7 +119,7 @@ class ShardRepository { } async updatePeerRecordLastSeenAndLastDialed(peerId, timestamp) { - await this.model.update( + return this.model.update( { lastDialed: timestamp, lastSeen: timestamp, diff --git a/src/service/sharding-table-service.js b/src/service/sharding-table-service.js index 2a09e598ef..00bab83bcc 100644 --- a/src/service/sharding-table-service.js +++ b/src/service/sharding-table-service.js @@ -214,15 +214,21 @@ class ShardingTableService { }; } if (this.memoryCachedPeerIds[peerId].lastUpdated < timestampThreshold) { - await this.repositoryModuleManager.updatePeerRecordLastSeenAndLastDialed(peerId, now); - this.memoryCachedPeerIds[peerId].lastUpdated = now; + const [rowsUpdated] = + await this.repositoryModuleManager.updatePeerRecordLastSeenAndLastDialed( + peerId, + now, + ); + if (rowsUpdated) { + this.memoryCachedPeerIds[peerId].lastUpdated = now; + } } this.memoryCachedPeerIds[peerId].lastDialed = now; this.memoryCachedPeerIds[peerId].lastSeen = now; } async updatePeerRecordLastDialed(peerId) { - const now = new Date(); + const now = Date.now(); const timestampThreshold = now - PEER_RECORD_UPDATE_DELAY; if (!this.memoryCachedPeerIds[peerId]) { this.memoryCachedPeerIds[peerId] = { @@ -232,8 +238,13 @@ class ShardingTableService { }; } if (this.memoryCachedPeerIds[peerId].lastUpdated < timestampThreshold) { - await this.repositoryModuleManager.updatePeerRecordLastDialed(peerId, now); - this.memoryCachedPeerIds[peerId].lastUpdated = now; + const [rowsUpdated] = await this.repositoryModuleManager.updatePeerRecordLastDialed( + peerId, + now, + ); + if (rowsUpdated) { + this.memoryCachedPeerIds[peerId].lastUpdated = now; + } } this.memoryCachedPeerIds[peerId].lastDialed = now; }