From 02a732c5115ece635a1284106b37bfac539e5978 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Tue, 11 Jan 2022 11:40:20 -0800 Subject: [PATCH] getProfiles: Fetch a maximum of three profiles at at a time --- ts/models/conversations.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ts/models/conversations.ts b/ts/models/conversations.ts index ec778012e..54ec0a995 100644 --- a/ts/models/conversations.ts +++ b/ts/models/conversations.ts @@ -4,6 +4,8 @@ /* eslint-disable camelcase */ import { compact, isNumber } from 'lodash'; import { batch as batchDispatch } from 'react-redux'; +import PQueue from 'p-queue'; + import type { ConversationAttributesType, ConversationModelCollectionType, @@ -4624,9 +4626,14 @@ export class ConversationModel extends window.Backbone // request all conversation members' keys const conversations = this.getMembers() as unknown as Array; - await Promise.all( - window._.map(conversations, conversation => - getProfile(conversation.get('uuid'), conversation.get('e164')) + + const queue = new PQueue({ + concurrency: 3, + }); + await queue.addAll( + conversations.map( + conversation => () => + getProfile(conversation.get('uuid'), conversation.get('e164')) ) ); }