Skip to content

Commit 7d109b8

Browse files
Review
1 parent 2d0a17b commit 7d109b8

File tree

5 files changed

+27
-22
lines changed

5 files changed

+27
-22
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -846,8 +846,8 @@ public QueryResult executeQuery(Query query, boolean usePreviousResults) {
846846
ImmutableSortedMap<DocumentKey, Document> documents =
847847
queryEngine.getDocumentsMatchingQuery(
848848
query,
849-
remoteKeys,
850-
usePreviousResults ? lastLimboFreeSnapshotVersion : SnapshotVersion.NONE);
849+
usePreviousResults ? lastLimboFreeSnapshotVersion : SnapshotVersion.NONE,
850+
remoteKeys);
851851
return new QueryResult(documents, remoteKeys);
852852
}
853853

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

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ public void initialize(LocalDocumentsView localDocumentsView, IndexManager index
8181

8282
public ImmutableSortedMap<DocumentKey, Document> getDocumentsMatchingQuery(
8383
Query query,
84-
ImmutableSortedSet<DocumentKey> remoteKeys,
85-
SnapshotVersion lastLimboFreeSnapshotVersion) {
84+
SnapshotVersion lastLimboFreeSnapshotVersion,
85+
ImmutableSortedSet<DocumentKey> remoteKeys) {
8686
hardAssert(initialized, "initialize() not called");
8787

8888
ImmutableSortedMap<DocumentKey, Document> result =
@@ -118,7 +118,8 @@ public ImmutableSortedMap<DocumentKey, Document> getDocumentsMatchingQuery(
118118
Set<DocumentKey> keys = indexManager.getDocumentsMatchingTarget(fieldIndex, target);
119119
ImmutableSortedMap<DocumentKey, Document> indexedDocuments =
120120
localDocumentsView.getDocuments(keys);
121-
return mergeResults(values(indexedDocuments), query, fieldIndex.getIndexState().getOffset());
121+
return appendRemainingResults(
122+
values(indexedDocuments), query, fieldIndex.getIndexState().getOffset());
122123
}
123124

124125
/**
@@ -158,7 +159,8 @@ && needsRefill(
158159
query.toString());
159160
}
160161

161-
return mergeResults(previousResults, query, IndexOffset.create(lastLimboFreeSnapshotVersion));
162+
return appendRemainingResults(
163+
previousResults, query, IndexOffset.create(lastLimboFreeSnapshotVersion));
162164
}
163165

164166
/** Applies the query filter and sorting to the provided documents. */
@@ -223,15 +225,18 @@ private ImmutableSortedMap<DocumentKey, Document> executeFullCollectionScan(Quer
223225
return localDocumentsView.getDocumentsMatchingQuery(query, IndexOffset.NONE);
224226
}
225227

226-
private ImmutableSortedMap<DocumentKey, Document> mergeResults(
227-
Iterable<Document> before, Query query, IndexOffset offset) {
228-
// Retrieve all results for documents that were updated since the last limbo-document free
229-
// remote snapshot.
230-
ImmutableSortedMap<DocumentKey, Document> after =
228+
/**
229+
* Combines the results from an indexed execution with the remaining documents that have not yet
230+
* been indexed.
231+
*/
232+
private ImmutableSortedMap<DocumentKey, Document> appendRemainingResults(
233+
Iterable<Document> indexedResults, Query query, IndexOffset offset) {
234+
// Retrieve all results for documents that were updated since the offset.
235+
ImmutableSortedMap<DocumentKey, Document> remainingResults =
231236
localDocumentsView.getDocumentsMatchingQuery(query, offset);
232-
for (Document entry : before) {
233-
after = after.insert(entry.getKey(), entry);
237+
for (Document entry : indexedResults) {
238+
remainingResults = remainingResults.insert(entry.getKey(), entry);
234239
}
235-
return after;
240+
return remainingResults;
236241
}
237242
}

firebase-firestore/src/test/java/com/google/firebase/firestore/local/CountingQueryEngine.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ public void initialize(LocalDocumentsView localDocuments, IndexManager indexMana
6868
@Override
6969
public ImmutableSortedMap<DocumentKey, Document> getDocumentsMatchingQuery(
7070
Query query,
71-
ImmutableSortedSet<DocumentKey> remoteKeys,
72-
SnapshotVersion lastLimboFreeSnapshotVersion) {
73-
return queryEngine.getDocumentsMatchingQuery(query, remoteKeys, lastLimboFreeSnapshotVersion);
71+
SnapshotVersion lastLimboFreeSnapshotVersion,
72+
ImmutableSortedSet<DocumentKey> remoteKeys) {
73+
return queryEngine.getDocumentsMatchingQuery(query, lastLimboFreeSnapshotVersion, remoteKeys);
7474
}
7575

7676
/** Returns the query engine that is used as the backing implementation. */

firebase-firestore/src/test/java/com/google/firebase/firestore/local/IndexedQueryEngineTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void combinesIndexedWithNonIndexedResults() {
9090
Query queryWithFilter = query("coll").filter(filter("foo", "==", true));
9191
ImmutableSortedMap<DocumentKey, Document> results =
9292
queryEngine.getDocumentsMatchingQuery(
93-
queryWithFilter, DocumentKey.emptyKeySet(), SnapshotVersion.NONE);
93+
queryWithFilter, SnapshotVersion.NONE, DocumentKey.emptyKeySet());
9494

9595
assertTrue(results.containsKey(doc1.getKey()));
9696
assertTrue(results.containsKey(doc2.getKey()));

firebase-firestore/src/test/java/com/google/firebase/firestore/local/QueryEngineTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ private DocumentSet runQuery(Query query, SnapshotVersion lastLimboFreeSnapshotV
185185
ImmutableSortedMap<DocumentKey, Document> docs =
186186
queryEngine.getDocumentsMatchingQuery(
187187
query,
188-
targetCache.getMatchingKeysForTargetId(TEST_TARGET_ID),
189-
lastLimboFreeSnapshotVersion);
188+
lastLimboFreeSnapshotVersion,
189+
targetCache.getMatchingKeysForTargetId(TEST_TARGET_ID));
190190
View view =
191191
new View(query, new ImmutableSortedSet<>(Collections.emptyList(), DocumentKey::compareTo));
192192
View.DocumentChanges viewDocChanges = view.computeDocChanges(docs);
@@ -405,8 +405,8 @@ public void doesNotIncludeDocumentsDeletedByMutation() throws Exception {
405405
() ->
406406
queryEngine.getDocumentsMatchingQuery(
407407
query,
408-
targetCache.getMatchingKeysForTargetId(TEST_TARGET_ID),
409-
LAST_LIMBO_FREE_SNAPSHOT));
408+
LAST_LIMBO_FREE_SNAPSHOT,
409+
targetCache.getMatchingKeysForTargetId(TEST_TARGET_ID)));
410410
assertEquals(emptyMutableDocumentMap().insert(MATCHING_DOC_A.getKey(), MATCHING_DOC_A), docs);
411411
}
412412
}

0 commit comments

Comments
 (0)