35
35
import com .google .firestore .v1 .Write .Builder ;
36
36
import com .google .protobuf .ByteString ;
37
37
import java .util .ArrayList ;
38
+ import java .util .Collections ;
38
39
import java .util .List ;
39
40
40
41
/** Serializer for values stored in the LocalStore. */
@@ -176,6 +177,9 @@ MutationBatch decodeMutationBatch(com.google.firebase.firestore.proto.WriteBatch
176
177
baseMutations .add (rpcSerializer .decodeMutation (batch .getBaseWrites (i )));
177
178
}
178
179
180
+ int mutationsCount = batch .getWritesCount ();
181
+ List <Mutation > mutations = new ArrayList <>(mutationsCount );
182
+
179
183
// Squash old transform mutations into existing patch or set mutations. The replacement of
180
184
// representing `transforms` with `update_transforms` on the SDK means that old `transform`
181
185
// mutations stored in IndexedDB need to be updated to `update_transforms`.
@@ -190,23 +194,16 @@ MutationBatch decodeMutationBatch(com.google.firebase.firestore.proto.WriteBatch
190
194
Write mutationToJoin = batch .getWrites (i - 1 );
191
195
Builder newMutationBuilder = Write .newBuilder (mutationToJoin );
192
196
for (FieldTransform fieldTransform : mutation .getTransform ().getFieldTransformsList ()) {
197
+
193
198
newMutationBuilder .addUpdateTransforms (fieldTransform );
194
199
}
195
- squashedBatchBuilder .addWrites (0 , newMutationBuilder .build ());
196
-
200
+ mutations .add (rpcSerializer .decodeMutation (newMutationBuilder .build ()));
197
201
--i ;
198
202
} else {
199
- squashedBatchBuilder . addWrites ( 0 , mutation );
203
+ mutations . add ( rpcSerializer . decodeMutation ( mutation ) );
200
204
}
201
205
}
202
-
203
- batch = squashedBatchBuilder .build ();
204
-
205
- int mutationsCount = batch .getWritesCount ();
206
- List <Mutation > mutations = new ArrayList <>(mutationsCount );
207
- for (int i = 0 ; i < mutationsCount ; i ++) {
208
- mutations .add (rpcSerializer .decodeMutation (batch .getWrites (i )));
209
- }
206
+ Collections .reverse (mutations );
210
207
return new MutationBatch (batchId , localWriteTime , baseMutations , mutations );
211
208
}
212
209
0 commit comments