From 82fa8e84af4799b4c4bef7089280aa15f1e67595 Mon Sep 17 00:00:00 2001 From: zeroxbt Date: Mon, 17 Jul 2023 22:26:23 +0200 Subject: [PATCH] fix update peer last seen and dialed --- .../repositories/shard-repository.js | 4 ++-- src/service/sharding-table-service.js | 21 ++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) 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; }