Skip to content

Commit 8c1b565

Browse files
author
Brian Chen
committed
fix nits
1 parent 107e911 commit 8c1b565

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

firebase-firestore/src/main/java/com/google/firebase/firestore/local/LocalSerializer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import com.google.firebase.firestore.model.UnknownDocument;
2929
import com.google.firebase.firestore.model.mutation.Mutation;
3030
import com.google.firebase.firestore.model.mutation.MutationBatch;
31-
import com.google.firebase.firestore.proto.WriteBatch;
3231
import com.google.firebase.firestore.remote.RemoteSerializer;
3332
import com.google.firestore.v1.DocumentTransform.FieldTransform;
3433
import com.google.firestore.v1.Write;
@@ -177,14 +176,12 @@ MutationBatch decodeMutationBatch(com.google.firebase.firestore.proto.WriteBatch
177176
baseMutations.add(rpcSerializer.decodeMutation(batch.getBaseWrites(i)));
178177
}
179178

180-
int mutationsCount = batch.getWritesCount();
181-
List<Mutation> mutations = new ArrayList<>(mutationsCount);
179+
List<Mutation> mutations = new ArrayList<>(batch.getWritesCount());
182180

183181
// Squash old transform mutations into existing patch or set mutations. The replacement of
184182
// representing `transforms` with `update_transforms` on the SDK means that old `transform`
185183
// mutations stored in IndexedDB need to be updated to `update_transforms`.
186184
// TODO(b/174608374): Remove this code once we perform a schema migration.
187-
WriteBatch.Builder squashedBatchBuilder = WriteBatch.newBuilder();
188185
for (int i = batch.getWritesCount() - 1; i >= 0; --i) {
189186
Write mutation = batch.getWrites(i);
190187
if (mutation.hasTransform()) {
@@ -194,7 +191,6 @@ MutationBatch decodeMutationBatch(com.google.firebase.firestore.proto.WriteBatch
194191
Write mutationToJoin = batch.getWrites(i - 1);
195192
Builder newMutationBuilder = Write.newBuilder(mutationToJoin);
196193
for (FieldTransform fieldTransform : mutation.getTransform().getFieldTransformsList()) {
197-
198194
newMutationBuilder.addUpdateTransforms(fieldTransform);
199195
}
200196
mutations.add(rpcSerializer.decodeMutation(newMutationBuilder.build()));
@@ -203,6 +199,10 @@ MutationBatch decodeMutationBatch(com.google.firebase.firestore.proto.WriteBatch
203199
mutations.add(rpcSerializer.decodeMutation(mutation));
204200
}
205201
}
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).
206206
Collections.reverse(mutations);
207207
return new MutationBatch(batchId, localWriteTime, baseMutations, mutations);
208208
}

0 commit comments

Comments
 (0)