Skip to content

Commit 107e911

Browse files
author
Brian Chen
committed
remove builder usage
1 parent b82f471 commit 107e911

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.google.firestore.v1.Write.Builder;
3636
import com.google.protobuf.ByteString;
3737
import java.util.ArrayList;
38+
import java.util.Collections;
3839
import java.util.List;
3940

4041
/** Serializer for values stored in the LocalStore. */
@@ -176,6 +177,9 @@ MutationBatch decodeMutationBatch(com.google.firebase.firestore.proto.WriteBatch
176177
baseMutations.add(rpcSerializer.decodeMutation(batch.getBaseWrites(i)));
177178
}
178179

180+
int mutationsCount = batch.getWritesCount();
181+
List<Mutation> mutations = new ArrayList<>(mutationsCount);
182+
179183
// Squash old transform mutations into existing patch or set mutations. The replacement of
180184
// representing `transforms` with `update_transforms` on the SDK means that old `transform`
181185
// mutations stored in IndexedDB need to be updated to `update_transforms`.
@@ -190,23 +194,16 @@ MutationBatch decodeMutationBatch(com.google.firebase.firestore.proto.WriteBatch
190194
Write mutationToJoin = batch.getWrites(i - 1);
191195
Builder newMutationBuilder = Write.newBuilder(mutationToJoin);
192196
for (FieldTransform fieldTransform : mutation.getTransform().getFieldTransformsList()) {
197+
193198
newMutationBuilder.addUpdateTransforms(fieldTransform);
194199
}
195-
squashedBatchBuilder.addWrites(0, newMutationBuilder.build());
196-
200+
mutations.add(rpcSerializer.decodeMutation(newMutationBuilder.build()));
197201
--i;
198202
} else {
199-
squashedBatchBuilder.addWrites(0, mutation);
203+
mutations.add(rpcSerializer.decodeMutation(mutation));
200204
}
201205
}
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);
210207
return new MutationBatch(batchId, localWriteTime, baseMutations, mutations);
211208
}
212209

0 commit comments

Comments
 (0)