@@ -138,34 +138,42 @@ class ParseObject extends ParseBase implements ParseCloneable {
138
138
final ParseResponse response = ParseResponse ();
139
139
return response;
140
140
}
141
+
141
142
if (object is ParseObject ) {
142
143
uniqueObjects.remove (object);
143
144
}
145
+
144
146
for (ParseFileBase file in uniqueFiles) {
145
147
final ParseResponse response = await file.save ();
146
148
if (! response.success) {
147
149
return response;
148
150
}
149
151
}
152
+
150
153
List <ParseObject > remaining = uniqueObjects.toList ();
151
154
final List <ParseObject > finished = < ParseObject > [];
155
+
152
156
final ParseResponse totalResponse = ParseResponse ()
153
157
..success = true
154
158
..results = < dynamic > []
155
159
..statusCode = 200 ;
160
+
156
161
while (remaining.isNotEmpty) {
157
162
/* Partition the objects into two sets: those that can be save immediately,
158
163
and those that rely on other objects to be created first. */
159
164
final List <ParseObject > current = < ParseObject > [];
160
165
final List <ParseObject > nextBatch = < ParseObject > [];
166
+
161
167
for (ParseObject object in remaining) {
162
168
if (object._canbeSerialized (finished)) {
163
169
current.add (object);
164
170
} else {
165
171
nextBatch.add (object);
166
172
}
167
173
}
174
+
168
175
remaining = nextBatch;
176
+
169
177
// TODO(yulingtianxia): lazy User
170
178
/* Batch requests have currently a limit of 50 packaged requests per single request
171
179
This splitting will split the overall array into segments of upto 50 requests
@@ -179,6 +187,7 @@ class ParseObject extends ParseBase implements ParseCloneable {
179
187
final List <dynamic > requests = chunk.map <dynamic >((ParseObject obj) {
180
188
return obj._getRequestJson (obj.objectId == null ? 'POST' : 'PUT' );
181
189
}).toList ();
190
+
182
191
for (ParseObject obj in chunk) {
183
192
obj._saveChanges ();
184
193
}
@@ -188,13 +197,19 @@ class ParseObject extends ParseBase implements ParseCloneable {
188
197
client: _client,
189
198
);
190
199
totalResponse.success & = response.success;
200
+
191
201
if (response.success) {
192
202
totalResponse.results! .addAll (response.results! );
193
203
totalResponse.count += response.count;
204
+
194
205
for (int i = 0 ; i < response.count; i++ ) {
195
206
if (response.results! [i] is ParseError ) {
196
207
// Batch request succeed, but part of batch failed.
197
208
chunk[i]._revertSavingChanges ();
209
+
210
+ // if any request in a batch requests group fails,
211
+ // then the overall response will be considered unsuccessful.
212
+ totalResponse.success = false ;
198
213
} else {
199
214
chunk[i]._savingChanges.clear ();
200
215
}
@@ -204,12 +219,15 @@ class ParseObject extends ParseBase implements ParseCloneable {
204
219
for (ParseObject obj in chunk) {
205
220
obj._revertSavingChanges ();
206
221
}
222
+
207
223
totalResponse.statusCode = response.statusCode;
208
224
totalResponse.error = response.error;
209
225
}
210
226
}
227
+
211
228
finished.addAll (current);
212
229
}
230
+
213
231
return totalResponse;
214
232
}
215
233
0 commit comments