Skip to content

Commit ef51d69

Browse files
authored
refactor: minor perf improvements (#497)
1 parent 77ef42c commit ef51d69

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

lib/cluster-adapter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,9 @@ export abstract class ClusterAdapterWithHeartbeat extends ClusterAdapter {
625625
}
626626

627627
override serverCount(): Promise<number> {
628+
const now = Date.now();
628629
this.nodesMap.forEach((lastSeen, uid) => {
629-
const nodeSeemsDown = Date.now() - lastSeen > this._opts.heartbeatTimeout;
630+
const nodeSeemsDown = now - lastSeen > this._opts.heartbeatTimeout;
630631
if (nodeSeemsDown) {
631632
debug("node %s seems down", uid);
632633
this.nodesMap.delete(uid);

lib/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ export class RedisAdapter extends Adapter {
908908
)
909909
).then((values) => {
910910
let numSub = 0;
911-
values.map((value) => {
911+
values.forEach((value) => {
912912
numSub += parseInt(value[1], 10);
913913
});
914914
return numSub;

lib/sharded-adapter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ class ShardedRedisAdapter extends ClusterAdapter {
118118
) {
119119
return Promise.all(
120120
this.pubClient.nodes().map((node) => {
121-
node.sendCommand(["PUBSUB", "SHARDNUMSUB", this.channel]);
121+
return node.sendCommand(["PUBSUB", "SHARDNUMSUB", this.channel]);
122122
})
123123
).then((values) => {
124124
let numSub = 0;
125-
values.map((value) => {
125+
values.forEach((value) => {
126126
numSub += parseInt(value[1], 10);
127127
});
128128
return numSub;

0 commit comments

Comments
 (0)