Skip to content

Commit 8f67c19

Browse files
committed
Feedback
1 parent 6b89ee1 commit 8f67c19

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,8 @@ private Map<DocumentKey, OverlayedDocument> computeViews(
158158
Set<DocumentKey> existenceStateChanged) {
159159
Map<DocumentKey, MutableDocument> recalculateDocuments = new HashMap<>();
160160
Map<DocumentKey, FieldMask> mutatedFields = new HashMap<>();
161-
Set<DocumentKey> keysWithOverlay = new HashSet<>();
162161
for (MutableDocument doc : docs.values()) {
163162
Overlay overlay = overlays.get(doc.getKey());
164-
if (overlay != null) {
165-
keysWithOverlay.add(doc.getKey());
166-
}
167163

168164
// Recalculate an overlay if the document's existence state is changed due to a remote
169165
// event *and* the overlay is a PatchMutation. This is because document existence state
@@ -179,6 +175,9 @@ private Map<DocumentKey, OverlayedDocument> computeViews(
179175
overlay
180176
.getMutation()
181177
.applyToLocalView(doc, overlay.getMutation().getFieldMask(), Timestamp.now());
178+
} else { // overlay == null
179+
// Using EMPTY to indicate there is no overlay for the document.
180+
mutatedFields.put(doc.getKey(), FieldMask.EMPTY);
182181
}
183182
}
184183

@@ -190,10 +189,7 @@ private Map<DocumentKey, OverlayedDocument> computeViews(
190189
for (Map.Entry<DocumentKey, MutableDocument> entry : docs.entrySet()) {
191190
result.put(
192191
entry.getKey(),
193-
new OverlayedDocument(
194-
entry.getValue(),
195-
keysWithOverlay.contains(entry.getKey()),
196-
mutatedFields.get(entry.getKey())));
192+
new OverlayedDocument(entry.getValue(), mutatedFields.get(entry.getKey())));
197193
}
198194
return result;
199195
}

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@
2121
/** Represents a local view (overlay) of a document, and the fields that are locally mutated. */
2222
public class OverlayedDocument {
2323
private Document overlayedDocument;
24-
private FieldMask mutatedFields;
25-
private boolean hasOverlay;
24+
@Nullable private FieldMask mutatedFields;
2625

27-
OverlayedDocument(Document overlayedDocument, boolean hasOverlay, FieldMask mutatedFields) {
26+
OverlayedDocument(Document overlayedDocument, FieldMask mutatedFields) {
2827
this.overlayedDocument = overlayedDocument;
2928
this.mutatedFields = mutatedFields;
30-
this.hasOverlay = hasOverlay;
3129
}
3230

3331
public Document getDocument() {
@@ -37,12 +35,13 @@ public Document getDocument() {
3735
/**
3836
* The fields that are locally mutated by patch mutations.
3937
*
40-
* <p>If hasOverlay() is true and the overlayed document is from set or delete mutations, this
41-
* returns null. If hasOverlay() is false, this returns FieldMask.EMPTY.
38+
* <p>If the overlayed document is from set or delete mutations, returns null.
39+
*
40+
* <p>If there is no overlay (mutation) for the document, returns FieldMask.EMPTY.
4241
*/
4342
// TODO(b/262245989): This screams for a proper sum type (Tagged Union) which does not exist in
4443
// Java (yet).
4544
public @Nullable FieldMask getMutatedFields() {
46-
return hasOverlay ? mutatedFields : FieldMask.EMPTY;
45+
return mutatedFields;
4746
}
4847
}

0 commit comments

Comments
 (0)