File tree 1 file changed +25
-7
lines changed
packages/baseai/src/deploy
1 file changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -1164,14 +1164,32 @@ export async function handleGitSyncMemoryDeploy({
1164
1164
documents : MemoryDocumentI [ ] ;
1165
1165
overwrite : boolean ;
1166
1166
} ) {
1167
- for ( const doc in documents ) {
1168
- await new Promise ( resolve => setTimeout ( resolve , 800 ) ) ; // To avoid rate limiting
1169
- await handleSingleDocDeploy ( {
1170
- memory,
1171
- account,
1172
- document : documents [ doc ] ,
1173
- overwrite : true // TODO: Implement overwrite for git-sync memories
1167
+ const BATCH_SIZE = 5 ;
1168
+ const RATE_LIMIT_DELAY = 1000 ;
1169
+
1170
+ // Fetch existing documents once
1171
+ const prodDocs = await listMemoryDocuments ( {
1172
+ account,
1173
+ memoryName : memory . name
1174
+ } ) ;
1175
+
1176
+ // Process in batches
1177
+ for ( let i = 0 ; i < documents . length ; i += BATCH_SIZE ) {
1178
+ const batch = documents . slice ( i , i + BATCH_SIZE ) ;
1179
+ const batchPromises = batch . map ( async ( doc , index ) => {
1180
+ await new Promise ( resolve =>
1181
+ setTimeout ( resolve , index * RATE_LIMIT_DELAY )
1182
+ ) ;
1183
+ return handleSingleDocDeploy ( {
1184
+ memory,
1185
+ account,
1186
+ document : doc ,
1187
+ overwrite : true ,
1188
+ prodDocs
1189
+ } ) ;
1174
1190
} ) ;
1191
+
1192
+ await Promise . all ( batchPromises ) ;
1175
1193
}
1176
1194
}
1177
1195
You can’t perform that action at this time.
0 commit comments