Skip to content

Commit c61f53c

Browse files
Feedback (next round)
1 parent c55cd93 commit c61f53c

File tree

7 files changed

+26
-28
lines changed

7 files changed

+26
-28
lines changed

firebase-firestore/src/main/java/com/google/firebase/firestore/core/View.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,7 @@ public DocumentChanges computeDocChanges(
158158
for (Map.Entry<DocumentKey, Document> entry : docChanges) {
159159
DocumentKey key = entry.getKey();
160160
Document oldDoc = oldDocumentSet.getDocument(key);
161-
Document newDoc = entry.getValue();
162-
163-
hardAssert(
164-
key.equals(entry.getKey()),
165-
"Mismatching key in doc change %s != %s",
166-
key,
167-
entry.getKey());
168-
169-
if (!query.matches(entry.getValue())) {
170-
newDoc = null;
171-
}
161+
Document newDoc = query.matches(entry.getValue()) ? entry.getValue() : null;
172162

173163
boolean oldDocHadPendingMutations =
174164
oldDoc != null && this.mutatedKeys.contains(oldDoc.getKey());

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,9 @@ private ImmutableSortedMap<DocumentKey, Document> getDocumentsMatchingCollection
207207
DocumentKey key = mutation.getKey();
208208
MutableDocument document = remoteDocuments.get(key);
209209
if (document == null) {
210+
// Create invalid document to apply mutations on top of
210211
document =
211-
new MutableDocument(key); // Create invalid document to apply mutations on top of
212+
new MutableDocument(key);
212213
remoteDocuments = remoteDocuments.insert(key, document);
213214
}
214215
mutation.applyToLocalView(document, batch.getLocalWriteTime());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ com.google.firebase.firestore.proto.MaybeDocument encodeMaybeDocument(MutableDoc
5656
} else if (document.isUnknownDocument()) {
5757
builder.setUnknownDocument(encodeUnknownDocument(document));
5858
} else {
59-
throw fail("Unknown Document %s", document);
59+
throw fail("Cannot encode invalid document %s", document);
6060
}
6161

6262
builder.setHasCommittedMutations(document.hasCommittedMutations());

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,20 @@ public ImmutableSortedMap<DocumentKey, MutableDocument> getAllDocumentsMatchingQ
9696
}
9797

9898
MutableDocument doc = entry.getValue().first;
99-
if (doc.isFoundDocument()) {
99+
if (!doc.isFoundDocument()) {
100+
continue;
101+
}
102+
100103
SnapshotVersion readTime = entry.getValue().second;
101104
if (readTime.compareTo(sinceReadTime) <= 0) {
102105
continue;
103106
}
104107

105-
if (query.matches(doc)) {
106-
result = result.insert(doc.getKey(), doc.clone());
108+
if (!query.matches(doc)) {
109+
continue;
107110
}
108-
}
111+
112+
result = result.insert(doc.getKey(), doc.clone())
109113
}
110114

111115
return result;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ interface RemoteDocumentCache {
3535
* <p>The cache key is extracted from {@code maybeDocument.key}. If there is already a cache entry
3636
* for the key, it will be replaced.
3737
*
38-
* @param document A Document or NoDocument to put in the cache.
38+
* @param document A document to put in the cache.
3939
* @param readTime The time at which the document was read or committed.
4040
*/
4141
void add(MutableDocument document, SnapshotVersion readTime);
@@ -47,16 +47,16 @@ interface RemoteDocumentCache {
4747
* Looks up an entry in the cache.
4848
*
4949
* @param documentKey The key of the entry to look up.
50-
* @return The cached Document or NoDocument entry, or an invalid document if nothing is cached.
50+
* @return The cached document entry, or an invalid document if nothing is cached.
5151
*/
5252
MutableDocument get(DocumentKey documentKey);
5353

5454
/**
5555
* Looks up a set of entries in the cache.
5656
*
5757
* @param documentKeys The keys of the entries to look up.
58-
* @return The cached Document or NoDocument entries indexed by key. If an entry is not cached, an
59-
* invalid document is returned.
58+
* @return The cached document entries indexed by key. If an entry is not cached, the
59+
* corresponding key will be mapped to an invalid document
6060
*/
6161
Map<DocumentKey, MutableDocument> getAll(Iterable<DocumentKey> documentKeys);
6262

@@ -66,7 +66,7 @@ interface RemoteDocumentCache {
6666
* <p>Implementations may return extra documents if convenient. The results should be re-filtered
6767
* by the consumer before presenting them to the user.
6868
*
69-
* <p>Cached NoDocument entries have no bearing on query results.
69+
* <p>Cached entries for non-existing documents have no bearing on query results.
7070
*
7171
* @param query The query to match documents against.
7272
* @param sinceReadTime If not set to SnapshotVersion.MIN, return only documents that have been

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void applyToRemoteDocument(
8484
DocumentKey documentKey, MutableDocument document, MutationBatchResult batchResult) {
8585
hardAssert(
8686
document.getKey().equals(documentKey),
87-
"applyToRemoteDocument: key %s doesn't match maybeDoc key %s",
87+
"applyToRemoteDocument: key %s doesn't match document key %s",
8888
documentKey,
8989
document.getKey());
9090

@@ -133,8 +133,7 @@ public ImmutableSortedMap<DocumentKey, Document> applyToLocalDocumentSet(
133133
// O(n).
134134
for (DocumentKey key : getKeys()) {
135135
// TODO(mutabledocuments): This method should take a map of MutableDocuments and we should
136-
// remove
137-
// this cast.
136+
// remove this cast.
138137
MutableDocument document = (MutableDocument) documentMap.get(key);
139138
applyToLocalView(document);
140139
if (!document.isValidDocument()) {

firebase-firestore/src/testUtil/java/com/google/firebase/firestore/testutil/TestUtil.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,19 @@ public static SnapshotVersion version(long versionMicros) {
183183
}
184184

185185
public static MutableDocument doc(String key, long version, Map<String, Object> data) {
186-
return new MutableDocument(key(key)).setFoundDocument(version(version), wrapObject(data));
186+
return doc(key(key), version, wrapObject(data));
187187
}
188188

189189
public static MutableDocument doc(DocumentKey key, long version, Map<String, Object> data) {
190-
return new MutableDocument(key).setFoundDocument(version(version), wrapObject(data));
190+
return doc(key, version, wrapObject(data));
191191
}
192192

193193
public static MutableDocument doc(String key, long version, ObjectValue data) {
194-
return new MutableDocument(key(key)).setFoundDocument(version(version), data);
194+
return doc(key(key), version, data);
195+
}
196+
197+
public static MutableDocument doc(DocumentKey key, long version, ObjectValue data) {
198+
return new MutableDocument(key).setFoundDocument(version(version), data);
195199
}
196200

197201
public static MutableDocument deletedDoc(String key, long version) {

0 commit comments

Comments
 (0)