Skip to content

Commit

Permalink
Merge pull request #1385 from drift-labs/chester/improve-update-walle…
Browse files Browse the repository at this point in the history
…t-speed

refactor(sdk): concurrently fetch user stats and user accounts
  • Loading branch information
ChesterSim authored Dec 16, 2024
2 parents 0e10baa + 54a2bd1 commit dc58e66
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions sdk/src/driftClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -776,16 +776,23 @@ export class DriftClient {
accountSubscription: this.userStatsAccountSubscriptionConfig,
});

await this.userStats.subscribe();
const subscriptionPromises: Promise<any>[] = [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;
}

Expand Down

0 comments on commit dc58e66

Please sign in to comment.