@@ -131,53 +131,72 @@ public async Task ImportAsync(ISyncService sync, SyncOptions options, ISession s
131
131
await uploader . CompleteAsync ( ) ;
132
132
}
133
133
134
- var request = new BulkUpdateAssetsDto ( ) ;
134
+ // Use separate batches to not cause issues with older Squidex version.
135
+ var annotateBatch = new BulkUpdateAssetsDto
136
+ {
137
+ Jobs = new List < BulkUpdateAssetsJobDto > ( )
138
+ } ;
135
139
136
140
foreach ( var asset in model . Assets )
137
141
{
138
- var parentId = await sync . Folders . GetIdAsync ( asset . FolderPath ) ;
139
-
140
- request . Jobs . Add ( asset . ToMove ( parentId ) ) ;
141
- request . Jobs . Add ( asset . ToAnnotate ( ) ) ;
142
+ annotateBatch . Jobs . Add ( asset . ToAnnotate ( ) ) ;
142
143
}
143
144
144
- var assetIndex = 0 ;
145
+ await ExecuteBatchAsync ( session , batchIndex , model , annotateBatch , "Annotating" ) ;
145
146
146
- var results = await session . Client . Assets . BulkUpdateAssetsAsync ( request ) ;
147
+ var moveBatch = new BulkUpdateAssetsDto
148
+ {
149
+ Jobs = new List < BulkUpdateAssetsJobDto > ( )
150
+ } ;
147
151
148
152
foreach ( var asset in model . Assets )
149
153
{
150
- // We create wo commands per asset.
151
- var result1 = results . FirstOrDefault ( x => x . JobIndex == ( assetIndex * 2 ) ) ;
152
- var result2 = results . FirstOrDefault ( x => x . JobIndex == ( assetIndex * 2 ) + 1 ) ;
153
-
154
- log . StepStart ( $ "Upserting #{ batchIndex } /{ assetIndex } ") ;
155
-
156
- if ( result1 ? . Error != null )
157
- {
158
- log . StepFailed ( result1 . Error . ToString ( ) ) ;
159
- }
160
- else if ( result2 ? . Error != null )
161
- {
162
- log . StepFailed ( result2 . Error . ToString ( ) ) ;
163
- }
164
- else if ( result1 ? . Id != null && result2 ? . Id != null )
165
- {
166
- log . StepSuccess ( ) ;
167
- }
168
- else
169
- {
170
- log . StepSkipped ( "Unknown Reason" ) ;
171
- }
154
+ var parentId = await sync . Folders . GetIdAsync ( asset . FolderPath ) ;
172
155
173
- assetIndex ++ ;
156
+ moveBatch . Jobs . Add ( asset . ToMove ( parentId ) ) ;
174
157
}
158
+
159
+ await ExecuteBatchAsync ( session , batchIndex , model , moveBatch , "Moving" ) ;
175
160
}
176
161
177
162
batchIndex ++ ;
178
163
}
179
164
}
180
165
166
+ private async Task ExecuteBatchAsync ( ISession session , int batchIndex , AssetsModel model , BulkUpdateAssetsDto request , string name )
167
+ {
168
+ var index = 0 ;
169
+ var results = await session . Client . Assets . BulkUpdateAssetsAsync ( request ) ;
170
+
171
+ foreach ( var asset in model . Assets )
172
+ {
173
+ // We create wo commands per asset.
174
+ var result1 = results . FirstOrDefault ( x => x . JobIndex == ( index * 2 ) ) ;
175
+ var result2 = results . FirstOrDefault ( x => x . JobIndex == ( index * 2 ) + 1 ) ;
176
+
177
+ log . StepStart ( $ "{ name } #{ batchIndex } /{ index } ") ;
178
+
179
+ if ( result1 ? . Error != null )
180
+ {
181
+ log . StepFailed ( result1 . Error . ToString ( ) ) ;
182
+ }
183
+ else if ( result2 ? . Error != null )
184
+ {
185
+ log . StepFailed ( result2 . Error . ToString ( ) ) ;
186
+ }
187
+ else if ( result1 ? . Id != null && result2 ? . Id != null )
188
+ {
189
+ log . StepSuccess ( ) ;
190
+ }
191
+ else
192
+ {
193
+ log . StepSkipped ( "Unknown Reason" ) ;
194
+ }
195
+
196
+ index ++ ;
197
+ }
198
+ }
199
+
181
200
private static IEnumerable < IFile > GetFiles ( IFileSystem fs )
182
201
{
183
202
foreach ( var file in fs . GetFiles ( new FilePath ( "assets" ) , ".json" ) )
0 commit comments