From 54a2bd148675ac7fd296141ea3486c5f68cdd25c Mon Sep 17 00:00:00 2001 From: Chester Sim Date: Tue, 17 Dec 2024 00:39:55 +0800 Subject: [PATCH] refactor(sdk): concurrently fetch user stats and user accounts --- sdk/src/driftClient.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/sdk/src/driftClient.ts b/sdk/src/driftClient.ts index 29abf5d2f..2df2efc25 100644 --- a/sdk/src/driftClient.ts +++ b/sdk/src/driftClient.ts @@ -776,16 +776,23 @@ export class DriftClient { accountSubscription: this.userStatsAccountSubscriptionConfig, }); - await this.userStats.subscribe(); + const subscriptionPromises: Promise[] = [this.userStats.subscribe()]; + let success = true; if (this.isSubscribed) { - await Promise.all(this.unsubscribeUsers()); - this.users.clear(); - success = await this.addAndSubscribeToUsers(); + const reSubscribeUsersPromise = async () => { + await Promise.all(this.unsubscribeUsers()); + this.users.clear(); + success = await this.addAndSubscribeToUsers(); + }; + + subscriptionPromises.push(reSubscribeUsersPromise()); } + await Promise.all(subscriptionPromises); + return success; }