Skip to content

Commit 47a213f

Browse files
WIP
1 parent 7bbc8a5 commit 47a213f

File tree

4 files changed

+9
-12
lines changed

4 files changed

+9
-12
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public LocalWriteResult writeLocally(List<Mutation> mutations) {
216216
() -> {
217217
// Load and apply all existing mutations. This lets us compute the current base state for
218218
// all non-idempotent transforms before applying any additional user-provided writes.
219-
ImmutableSortedMap<DocumentKey, Document> existingDocuments =
219+
ImmutableSortedMap<DocumentKey, Document> documents =
220220
localDocuments.getDocuments(keys);
221221

222222
// For non-idempotent mutations (such as `FieldValue.increment()`), we record the base
@@ -226,7 +226,7 @@ public LocalWriteResult writeLocally(List<Mutation> mutations) {
226226
List<Mutation> baseMutations = new ArrayList<>();
227227
for (Mutation mutation : mutations) {
228228
ObjectValue baseValue =
229-
mutation.extractTransformBaseValue(existingDocuments.get(mutation.getKey()));
229+
mutation.extractTransformBaseValue(documents.get(mutation.getKey()));
230230
if (baseValue != null) {
231231
// NOTE: The base state should only be applied if there's some existing
232232
// document to override, so use a Precondition of exists=true
@@ -241,9 +241,8 @@ public LocalWriteResult writeLocally(List<Mutation> mutations) {
241241

242242
MutationBatch batch =
243243
mutationQueue.addMutationBatch(localWriteTime, baseMutations, mutations);
244-
ImmutableSortedMap<DocumentKey, Document> changedDocuments =
245-
batch.applyToLocalDocumentSet(existingDocuments);
246-
return new LocalWriteResult(batch.getBatchId(), changedDocuments);
244+
batch.applyToLocalDocumentSet(documents);
245+
return new LocalWriteResult(batch.getBatchId(), documents);
247246
});
248247
}
249248

firebase-firestore/src/main/java/com/google/firebase/firestore/model/Values.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,12 +386,12 @@ private static void canonifyArray(StringBuilder builder, ArrayValue arrayValue)
386386
builder.append("]");
387387
}
388388

389-
/** Returns true if `value` is either a INTEGER_VALUE. */
389+
/** Returns true if `value` is a INTEGER_VALUE. */
390390
public static boolean isInteger(@Nullable Value value) {
391391
return value != null && value.getValueTypeCase() == Value.ValueTypeCase.INTEGER_VALUE;
392392
}
393393

394-
/** Returns true if `value` is either a DOUBLE_VALUE. */
394+
/** Returns true if `value` is a DOUBLE_VALUE. */
395395
public static boolean isDouble(@Nullable Value value) {
396396
return value != null && value.getValueTypeCase() == Value.ValueTypeCase.DOUBLE_VALUE;
397397
}

firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/MutationBatch.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public void applyToLocalView(MutableDocument document) {
118118
}
119119

120120
/** Computes the local view for all provided documents given the mutations in this batch. */
121-
public ImmutableSortedMap<DocumentKey, Document> applyToLocalDocumentSet(
121+
public void applyToLocalDocumentSet(
122122
ImmutableSortedMap<DocumentKey, Document> documentMap) {
123123
// TODO(mrschmidt): This implementation is O(n^2). If we iterate through the mutations first
124124
// (as done in `applyToLocalView(MutableDocument d)`), we can reduce the complexity to
@@ -131,9 +131,7 @@ public ImmutableSortedMap<DocumentKey, Document> applyToLocalDocumentSet(
131131
if (!document.isValidDocument()) {
132132
document.convertToNoDocument(SnapshotVersion.NONE);
133133
}
134-
documentMap = documentMap.insert(document.getKey(), document);
135134
}
136-
return documentMap;
137135
}
138136

139137
@Override

firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/PatchMutation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public void applyToRemoteDocument(MutableDocument document, MutationResult mutat
119119
applyServerTransformResults(value, document, mutationResult.getTransformResults());
120120
value.setAll(getPatch());
121121
document
122-
.convertToFoundDocument(mutationResult.getVersion(), document.getData())
122+
.convertToFoundDocument(mutationResult.getVersion(), value)
123123
.setHasCommittedMutations();
124124
}
125125

@@ -135,7 +135,7 @@ public void applyToLocalView(MutableDocument document, Timestamp localWriteTime)
135135
applyLocalTransformResults(value, document, localWriteTime);
136136
value.setAll(getPatch());
137137
document
138-
.convertToFoundDocument(getPostMutationVersion(document), document.getData())
138+
.convertToFoundDocument(getPostMutationVersion(document), value)
139139
.setHasLocalMutations();
140140
}
141141

0 commit comments

Comments
 (0)