Skip to content

Commit 13b12ca

Browse files
Remove SimpleQueryEngine (#2203)
* Remove SimpleQueryEngine * Renames
1 parent 0c1b7b6 commit 13b12ca

File tree

9 files changed

+57
-150
lines changed

9 files changed

+57
-150
lines changed

firebase-firestore/src/androidTest/java/com/google/firebase/firestore/remote/RemoteStoreTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
import com.google.firebase.database.collection.ImmutableSortedSet;
2222
import com.google.firebase.firestore.auth.User;
2323
import com.google.firebase.firestore.core.OnlineState;
24+
import com.google.firebase.firestore.local.DefaultQueryEngine;
2425
import com.google.firebase.firestore.local.LocalStore;
2526
import com.google.firebase.firestore.local.MemoryPersistence;
2627
import com.google.firebase.firestore.local.Persistence;
27-
import com.google.firebase.firestore.local.SimpleQueryEngine;
2828
import com.google.firebase.firestore.model.DocumentKey;
2929
import com.google.firebase.firestore.model.mutation.MutationBatchResult;
3030
import com.google.firebase.firestore.testutil.IntegrationTestUtil;
@@ -74,7 +74,7 @@ public ImmutableSortedSet<DocumentKey> getRemoteKeysForTarget(int targetId) {
7474
};
7575

7676
FakeConnectivityMonitor connectivityMonitor = new FakeConnectivityMonitor();
77-
SimpleQueryEngine queryEngine = new SimpleQueryEngine();
77+
DefaultQueryEngine queryEngine = new DefaultQueryEngine();
7878
Persistence persistence = MemoryPersistence.createEagerGcMemoryPersistence();
7979
persistence.start();
8080
LocalStore localStore = new LocalStore(persistence, queryEngine, User.UNAUTHENTICATED);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
import androidx.annotation.Nullable;
1818
import com.google.firebase.database.collection.ImmutableSortedSet;
19+
import com.google.firebase.firestore.local.DefaultQueryEngine;
1920
import com.google.firebase.firestore.local.GarbageCollectionScheduler;
20-
import com.google.firebase.firestore.local.IndexFreeQueryEngine;
2121
import com.google.firebase.firestore.local.LocalStore;
2222
import com.google.firebase.firestore.local.MemoryPersistence;
2323
import com.google.firebase.firestore.local.Persistence;
@@ -49,7 +49,7 @@ protected EventManager createEventManager(Configuration configuration) {
4949
@Override
5050
protected LocalStore createLocalStore(Configuration configuration) {
5151
return new LocalStore(
52-
getPersistence(), new IndexFreeQueryEngine(), configuration.getInitialUser());
52+
getPersistence(), new DefaultQueryEngine(), configuration.getInitialUser());
5353
}
5454

5555
@Override

firebase-firestore/src/main/java/com/google/firebase/firestore/local/IndexFreeQueryEngine.java renamed to firebase-firestore/src/main/java/com/google/firebase/firestore/local/DefaultQueryEngine.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,25 @@
2727
import java.util.Collections;
2828
import java.util.Map;
2929

30-
// TOOD(b/140938512): Drop SimpleQueryEngine and rename IndexFreeQueryEngine.
31-
3230
/**
33-
* A query engine that takes advantage of the target document mapping in the TargetCache. The
34-
* IndexFreeQueryEngine optimizes query execution by only reading the documents that previously
35-
* matched a query plus any documents that were edited after the query was last listened to.
31+
* A query engine that takes advantage of the target document mapping in the TargetCache. Query
32+
* execution is optimized by only reading the documents that previously matched a query plus any
33+
* documents that were edited after the query was last listened to.
3634
*
37-
* <p>There are some cases where Index-Free queries are not guaranteed to produce the same results
38-
* as full collection scans. In these cases, the IndexFreeQueryEngine falls back to full query
39-
* processing. These cases are:
35+
* <p>There are some cases where this optimization is not guaranteed to produce the same results as
36+
* full collection scans. In these cases, query processing falls back to full scans. These cases
37+
* are:
4038
*
4139
* <ol>
42-
* <il>Limit queries where a document that matched the query previously no longer matches the
43-
* query. <il> Limit queries where a document edit may cause the document to sort below another
44-
* document that is in the local cache. <il>Queries that have never been CURRENT or free of Limbo
45-
* documents.
40+
* <li>Limit queries where a document that matched the query previously no longer matches the
41+
* query.
42+
* <li>Limit queries where a document edit may cause the document to sort below another document
43+
* that is in the local cache.
44+
* <li>Queries that have never been CURRENT or free of limbo documents.
4645
* </ol>
4746
*/
48-
public class IndexFreeQueryEngine implements QueryEngine {
49-
private static final String LOG_TAG = "IndexFreeQueryEngine";
47+
public class DefaultQueryEngine implements QueryEngine {
48+
private static final String LOG_TAG = "DefaultQueryEngine";
5049

5150
private LocalDocumentsView localDocumentsView;
5251

@@ -62,7 +61,7 @@ public ImmutableSortedMap<DocumentKey, Document> getDocumentsMatchingQuery(
6261
ImmutableSortedSet<DocumentKey> remoteKeys) {
6362
hardAssert(localDocumentsView != null, "setLocalDocumentsView() not called");
6463

65-
// Queries that match all documents don't benefit from using IndexFreeQueries. It is more
64+
// Queries that match all documents don't benefit from using key-based lookups. It is more
6665
// efficient to scan all documents in a collection, rather than to perform individual lookups.
6766
if (query.matchesAllDocuments()) {
6867
return executeFullCollectionScan(query);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ ImmutableSortedMap<DocumentKey, MaybeDocument> getLocalViewOfDocuments(
142142
return results;
143143
}
144144

145-
// TODO: The Querying implementation here should move 100% to SimpleQueryEngine.
145+
// TODO: The Querying implementation here should move 100% to the query engines.
146146
// Instead, we should just provide a getCollectionDocuments() method here that return all the
147-
// documents in a given collection so that SimpleQueryEngine can do that and then filter in
147+
// documents in a given collection so that query engine can do that and then filter in
148148
// memory.
149149

150150
/**

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

Lines changed: 0 additions & 56 deletions
This file was deleted.

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ public abstract class LocalStoreTestCase {
9999
private @Nullable QueryResult lastQueryResult;
100100
private int lastTargetId;
101101

102-
abstract QueryEngine getQueryEngine();
103-
104102
abstract Persistence getPersistence();
105103

106104
abstract boolean garbageCollectorIsEager();
@@ -113,7 +111,7 @@ public void setUp() {
113111
lastTargetId = 0;
114112

115113
localStorePersistence = getPersistence();
116-
queryEngine = new CountingQueryEngine(getQueryEngine());
114+
queryEngine = new CountingQueryEngine(new DefaultQueryEngine());
117115
localStore = new LocalStore(localStorePersistence, queryEngine, User.UNAUTHENTICATED);
118116
localStore.start();
119117
}
@@ -1023,7 +1021,7 @@ public void testHandlesSetMutationThenAckThenTransformMutationThenAckThenTransfo
10231021
@Test
10241022
public void testUsesTargetMappingToExecuteQueries() {
10251023
assumeFalse(garbageCollectorIsEager());
1026-
assumeTrue(queryEngine.getSubject() instanceof IndexFreeQueryEngine);
1024+
assumeTrue(queryEngine.getSubject() instanceof DefaultQueryEngine);
10271025

10281026
// This test verifies that once a target mapping has been written, only documents that match
10291027
// the query are read from the RemoteDocumentCache.

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

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,19 @@
1414

1515
package com.google.firebase.firestore.local;
1616

17-
import java.util.Arrays;
18-
import java.util.Collection;
1917
import org.junit.runner.RunWith;
20-
import org.robolectric.ParameterizedRobolectricTestRunner;
18+
import org.robolectric.RobolectricTestRunner;
2119
import org.robolectric.annotation.Config;
2220

23-
@RunWith(ParameterizedRobolectricTestRunner.class)
21+
@RunWith(RobolectricTestRunner.class)
2422
@Config(manifest = Config.NONE)
2523
public class MemoryLocalStoreTest extends LocalStoreTestCase {
2624

27-
private QueryEngine queryEngine;
28-
29-
@ParameterizedRobolectricTestRunner.Parameters(name = "QueryEngine = {0}")
30-
public static Collection<Object[]> data() {
31-
return Arrays.asList(
32-
new Object[] {new SimpleQueryEngine()}, new Object[] {new IndexFreeQueryEngine()});
33-
}
34-
35-
public MemoryLocalStoreTest(QueryEngine queryEngine) {
36-
this.queryEngine = queryEngine;
37-
}
38-
3925
@Override
4026
Persistence getPersistence() {
4127
return PersistenceTestHelpers.createEagerGCMemoryPersistence();
4228
}
4329

44-
@Override
45-
QueryEngine getQueryEngine() {
46-
return this.queryEngine;
47-
}
48-
4930
@Override
5031
boolean garbageCollectorIsEager() {
5132
return true;

0 commit comments

Comments
 (0)