From 4c097d4e171632971eae6852ea21e88cc4ee42e5 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 14 Apr 2021 19:10:55 +0200 Subject: [PATCH] add queueMinuteTimestamp --- src/ws/identify.ts | 1 + src/ws/process_queue.ts | 7 +++++++ src/ws/spawn_shards.ts | 2 +- src/ws/ws.ts | 2 ++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/ws/identify.ts b/src/ws/identify.ts index b64be1a21..6a6486195 100644 --- a/src/ws/identify.ts +++ b/src/ws/identify.ts @@ -33,6 +33,7 @@ export async function identify(shardId: number, maxShards: number) { }, queue: [], processingQueue: false, + queueMinuteTimestamp: 0, }); socket.onopen = () => { diff --git a/src/ws/process_queue.ts b/src/ws/process_queue.ts index 7a37b3ead..3737e58b1 100644 --- a/src/ws/process_queue.ts +++ b/src/ws/process_queue.ts @@ -7,6 +7,7 @@ export async function processQueue(id: number) { if (!shard?.queue.length || shard.processingQueue) return; shard.processingQueue = true; + shard.queueMinuteTimestamp = Date.now(); let counter = 0; @@ -16,6 +17,12 @@ export async function processQueue(id: number) { return; } + const now = Date.now(); + if (now - shard.queueMinuteTimestamp > 60000) { + shard.queueMinuteTimestamp = now; + counter = 0; + } + // Send a request that is next in line const request = shard.queue.shift(); diff --git a/src/ws/spawn_shards.ts b/src/ws/spawn_shards.ts index d82c15d88..437556af6 100644 --- a/src/ws/spawn_shards.ts +++ b/src/ws/spawn_shards.ts @@ -61,7 +61,7 @@ export function spawnShards(firstShardId = 0) { while (shardId !== undefined) { ws.log("DEBUG", "Running while loop in getMembers function."); - await ws.tellClusterToIdentify(clusterId as number, shardId, bucketId); + await ws.tellClusterToIdentify(clusterId, shardId, bucketId); shardId = queue.shift(); } } diff --git a/src/ws/ws.ts b/src/ws/ws.ts index 1db6c8a74..22fc68d68 100644 --- a/src/ws/ws.ts +++ b/src/ws/ws.ts @@ -145,6 +145,8 @@ export interface DiscordenoShard { queue: WebSocketRequest[]; /** Whether or not the queue for this shard is being processed. */ processingQueue: boolean; + /** When the first request for this minute has been sent. */ + queueMinuteTimestamp: number; } export interface WebSocketRequest {