Skip to content

Commit cb297fb

Browse files
committed
More more code to delete.
1 parent 11dd88b commit cb297fb

File tree

1 file changed

+1
-81
lines changed

1 file changed

+1
-81
lines changed

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

Lines changed: 1 addition & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,9 @@ private ImmutableSortedMap<DocumentKey, Document> getDocumentsMatchingCollection
248248
return results;
249249
}
250250

251+
/** Queries the remote documents and overlays by doing a full collection scan. */
251252
private ImmutableSortedMap<DocumentKey, Document> getDocumentsMatchingCollectionQuery(
252253
Query query, IndexOffset offset) {
253-
return getDocumentsMatchingCollectionQueryFromOverlayCache(query, offset);
254-
}
255-
256-
/** Queries the remote documents and overlays by doing a full collection scan. */
257-
private ImmutableSortedMap<DocumentKey, Document>
258-
getDocumentsMatchingCollectionQueryFromOverlayCache(Query query, IndexOffset offset) {
259254
ImmutableSortedMap<DocumentKey, MutableDocument> remoteDocuments =
260255
remoteDocumentCache.getAllDocumentsMatchingQuery(query, offset);
261256
Map<DocumentKey, Mutation> overlays = documentOverlayCache.getOverlays(query.getPath(), -1);
@@ -288,79 +283,4 @@ private ImmutableSortedMap<DocumentKey, Document> getDocumentsMatchingCollection
288283

289284
return results;
290285
}
291-
292-
/** Queries the remote documents and mutation queue, by doing a full collection scan. */
293-
private ImmutableSortedMap<DocumentKey, Document>
294-
getDocumentsMatchingCollectionQueryFromMutationQueue(Query query, IndexOffset offset) {
295-
ImmutableSortedMap<DocumentKey, MutableDocument> remoteDocuments =
296-
remoteDocumentCache.getAllDocumentsMatchingQuery(query, offset);
297-
298-
// TODO(indexing): We should plumb sinceReadTime through to the mutation queue
299-
List<MutationBatch> matchingBatches = mutationQueue.getAllMutationBatchesAffectingQuery(query);
300-
301-
remoteDocuments = addMissingBaseDocuments(matchingBatches, remoteDocuments);
302-
303-
for (MutationBatch batch : matchingBatches) {
304-
for (Mutation mutation : batch.getMutations()) {
305-
// Only process documents belonging to the collection.
306-
if (!query.getPath().isImmediateParentOf(mutation.getKey().getPath())) {
307-
continue;
308-
}
309-
310-
DocumentKey key = mutation.getKey();
311-
MutableDocument document = remoteDocuments.get(key);
312-
if (document == null) {
313-
// Create invalid document to apply mutations on top of
314-
document = MutableDocument.newInvalidDocument(key);
315-
remoteDocuments = remoteDocuments.insert(key, document);
316-
}
317-
mutation.applyToLocalView(
318-
document, FieldMask.fromSet(new HashSet<>()), batch.getLocalWriteTime());
319-
if (!document.isFoundDocument()) {
320-
remoteDocuments = remoteDocuments.remove(key);
321-
}
322-
}
323-
}
324-
325-
ImmutableSortedMap<DocumentKey, Document> results = emptyDocumentMap();
326-
for (Map.Entry<DocumentKey, MutableDocument> docEntry : remoteDocuments) {
327-
// Finally, insert the documents that still match the query
328-
if (query.matches(docEntry.getValue())) {
329-
results = results.insert(docEntry.getKey(), docEntry.getValue());
330-
}
331-
}
332-
333-
return results;
334-
}
335-
336-
/**
337-
* It is possible that a {@code PatchMutation} can make a document match a query, even if the
338-
* version in the {@code RemoteDocumentCache} is not a match yet (waiting for server to ack). To
339-
* handle this, we find all document keys affected by the {@code PatchMutation}s that are not in
340-
* {@code existingDocs} yet, and back fill them via {@code remoteDocumentCache.getAll}, otherwise
341-
* those {@code PatchMutation}s will be ignored because no base document can be found, and lead to
342-
* missing results for the query.
343-
*/
344-
private ImmutableSortedMap<DocumentKey, MutableDocument> addMissingBaseDocuments(
345-
List<MutationBatch> matchingBatches,
346-
ImmutableSortedMap<DocumentKey, MutableDocument> existingDocs) {
347-
HashSet<DocumentKey> missingDocKeys = new HashSet<>();
348-
for (MutationBatch batch : matchingBatches) {
349-
for (Mutation mutation : batch.getMutations()) {
350-
if (mutation instanceof PatchMutation && !existingDocs.containsKey(mutation.getKey())) {
351-
missingDocKeys.add(mutation.getKey());
352-
}
353-
}
354-
}
355-
356-
ImmutableSortedMap<DocumentKey, MutableDocument> mergedDocs = existingDocs;
357-
Map<DocumentKey, MutableDocument> missingDocs = remoteDocumentCache.getAll(missingDocKeys);
358-
for (Map.Entry<DocumentKey, MutableDocument> entry : missingDocs.entrySet()) {
359-
if (entry.getValue().isFoundDocument()) {
360-
mergedDocs = mergedDocs.insert(entry.getKey(), entry.getValue());
361-
}
362-
}
363-
364-
return mergedDocs;
365-
}
366286
}

0 commit comments

Comments
 (0)