28
28
import com .google .firebase .firestore .model .UnknownDocument ;
29
29
import com .google .firebase .firestore .model .mutation .Mutation ;
30
30
import com .google .firebase .firestore .model .mutation .MutationBatch ;
31
- import com .google .firebase .firestore .proto .WriteBatch ;
32
31
import com .google .firebase .firestore .remote .RemoteSerializer ;
33
32
import com .google .firestore .v1 .DocumentTransform .FieldTransform ;
34
33
import com .google .firestore .v1 .Write ;
@@ -177,14 +176,12 @@ MutationBatch decodeMutationBatch(com.google.firebase.firestore.proto.WriteBatch
177
176
baseMutations .add (rpcSerializer .decodeMutation (batch .getBaseWrites (i )));
178
177
}
179
178
180
- int mutationsCount = batch .getWritesCount ();
181
- List <Mutation > mutations = new ArrayList <>(mutationsCount );
179
+ List <Mutation > mutations = new ArrayList <>(batch .getWritesCount ());
182
180
183
181
// Squash old transform mutations into existing patch or set mutations. The replacement of
184
182
// representing `transforms` with `update_transforms` on the SDK means that old `transform`
185
183
// mutations stored in IndexedDB need to be updated to `update_transforms`.
186
184
// TODO(b/174608374): Remove this code once we perform a schema migration.
187
- WriteBatch .Builder squashedBatchBuilder = WriteBatch .newBuilder ();
188
185
for (int i = batch .getWritesCount () - 1 ; i >= 0 ; --i ) {
189
186
Write mutation = batch .getWrites (i );
190
187
if (mutation .hasTransform ()) {
@@ -194,7 +191,6 @@ MutationBatch decodeMutationBatch(com.google.firebase.firestore.proto.WriteBatch
194
191
Write mutationToJoin = batch .getWrites (i - 1 );
195
192
Builder newMutationBuilder = Write .newBuilder (mutationToJoin );
196
193
for (FieldTransform fieldTransform : mutation .getTransform ().getFieldTransformsList ()) {
197
-
198
194
newMutationBuilder .addUpdateTransforms (fieldTransform );
199
195
}
200
196
mutations .add (rpcSerializer .decodeMutation (newMutationBuilder .build ()));
@@ -203,6 +199,10 @@ MutationBatch decodeMutationBatch(com.google.firebase.firestore.proto.WriteBatch
203
199
mutations .add (rpcSerializer .decodeMutation (mutation ));
204
200
}
205
201
}
202
+
203
+ // Reverse the mutations to preserve the original ordering since the above for-loop iterates in
204
+ // reverse order. We use reverse() instead of prepending the elements into the mutations array
205
+ // since prepending to a List is O(n).
206
206
Collections .reverse (mutations );
207
207
return new MutationBatch (batchId , localWriteTime , baseMutations , mutations );
208
208
}
0 commit comments