Futa Arai 2 лет назад
Родитель
Сommit
fb5199cd01

+ 1 - 1
apps/app/src/features/external-user-group/server/service/external-user-group-sync.ts

@@ -15,7 +15,7 @@ import ExternalUserGroupRelation from '../models/external-user-group-relation';
 // Max space complexity of syncExternalUserGroups will be:
 // O(TREES_BATCH_SIZE * d * USERS_BATCH_SIZE)
 const TREES_BATCH_SIZE = 10;
-const USERS_BATCH_SIZE = 100;
+const USERS_BATCH_SIZE = 30;
 
 abstract class ExternalUserGroupSyncService {
 

+ 1 - 1
apps/app/src/features/external-user-group/server/service/ldap-user-group-sync.ts

@@ -13,7 +13,7 @@ import ExternalUserGroupSyncService from './external-user-group-sync';
 // Max space complexity of generateExternalUserGroupTrees will be:
 // O(TREES_BATCH_SIZE * d * USERS_BATCH_SIZE)
 const TREES_BATCH_SIZE = 10;
-const USERS_BATCH_SIZE = 100;
+const USERS_BATCH_SIZE = 30;
 
 class LdapUserGroupSyncService extends ExternalUserGroupSyncService {
 

+ 10 - 1
apps/app/src/utils/promise.spec.ts

@@ -8,12 +8,21 @@ describe('batchProcessPromiseAll', () => {
 
     const all = [...batch1, ...batch2, ...batch3];
 
-    const result = await batchProcessPromiseAll(all, 5, async(num) => {
+    const actualProcessedBatches: number[][] = [];
+    const result = await batchProcessPromiseAll(all, 5, async(num, i, arr) => {
+      if (arr != null && i === 0) {
+        actualProcessedBatches.push(arr);
+      }
       return num * 10;
     });
 
     const expected = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120];
 
     expect(result).toStrictEqual(expected);
+    expect(actualProcessedBatches).toStrictEqual([
+      batch1,
+      batch2,
+      batch3,
+    ]);
   });
 });

+ 1 - 1
apps/app/src/utils/promise.ts

@@ -9,7 +9,7 @@
 export const batchProcessPromiseAll = async<I, O>(
   items: Array<I>,
   limit: number,
-  fn: (item: I) => Promise<O>,
+  fn: (item: I, index?: number, array?: Array<I>) => Promise<O>,
 ): Promise<O[]> => {
   let results: O[] = [];
   for (let start = 0; start < items.length; start += limit) {