From d94ee8258cd49341aca9179b29c82e20548e2aad Mon Sep 17 00:00:00 2001 From: Priyank Saxena Date: Thu, 27 Aug 2020 20:02:34 +0000 Subject: [PATCH] Merged PR 1177: [CC v2.1] Optimize GetUserDataEntitiesByIds Activity **Issue :** Fan In/Fan Out pattern in GetUserDataEntitiesByIds is creating multiple function, exhausting free function execution count, and adding 0.20$ extra cost for every 1 million messages sent. **Changes :** Get the user data sequentially for each group members. This change is targeting to bring down function execution count by 50% and the overall function cost. --- .../GetUserDataEntitiesByIdsActivity.cs | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/Source/Microsoft.Teams.Apps.CompanyCommunicator.Prep.Func/PreparingToSend/GetRecipientDataBatches/GetUserDataEntitiesByIdsActivity.cs b/Source/Microsoft.Teams.Apps.CompanyCommunicator.Prep.Func/PreparingToSend/GetRecipientDataBatches/GetUserDataEntitiesByIdsActivity.cs index 17066d705..fe498e97d 100644 --- a/Source/Microsoft.Teams.Apps.CompanyCommunicator.Prep.Func/PreparingToSend/GetRecipientDataBatches/GetUserDataEntitiesByIdsActivity.cs +++ b/Source/Microsoft.Teams.Apps.CompanyCommunicator.Prep.Func/PreparingToSend/GetRecipientDataBatches/GetUserDataEntitiesByIdsActivity.cs @@ -44,18 +44,10 @@ public async Task> RunAsync( { try { - var tasks = new List>(); - foreach (var aadId in userAadIds) - { - var task = context.CallActivityWithRetryAsync( - nameof(GetUserDataEntitiesByIdsActivity.GetUserDataEntityAsync), - ActivitySettings.CommonActivityRetryOptions, - aadId); - tasks.Add(task); - } - - var userEntities = await Task.WhenAll(tasks); - return userEntities; + return await context.CallActivityWithRetryAsync>( + nameof(GetUserDataEntitiesByIdsActivity.GetUserDataEntitiesAsync), + ActivitySettings.CommonActivityRetryOptions, + userAadIds); } catch (Exception ex) { @@ -70,14 +62,21 @@ public async Task> RunAsync( /// This method represents the "get user data entity" durable activity. /// It gets installed user data. /// - /// User's Aad Id. + /// list of user Aad Id. /// It returns the installed user data entity. - [FunctionName(nameof(GetUserDataEntityAsync))] - public async Task GetUserDataEntityAsync( - [ActivityTrigger] string aadId) + [FunctionName(nameof(GetUserDataEntitiesAsync))] + public async Task> GetUserDataEntitiesAsync( + [ActivityTrigger] IEnumerable userAadIds) { - return await this.userDataRepository. - GetAsync(UserDataTableNames.UserDataPartition, aadId); + var userDataEntities = new List(); + foreach (var aadId in userAadIds) + { + var userDataEntity = await this.userDataRepository. + GetAsync(UserDataTableNames.UserDataPartition, aadId); + userDataEntities.Add(userDataEntity); + } + + return userDataEntities; } } }