Skip to content

Commit 93e8be1

Browse files
committed
Remove interface
1 parent 1533399 commit 93e8be1

File tree

8 files changed

+34
-59
lines changed

8 files changed

+34
-59
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ public ImmutableSortedSet<DocumentKey> getRemoteKeysForTarget(int targetId) {
7878
QueryEngine queryEngine = new QueryEngine();
7979
Persistence persistence = MemoryPersistence.createEagerGcMemoryPersistence();
8080
persistence.start();
81-
LocalStore localStore =
82-
new LocalStore(persistence, queryEngine, User.UNAUTHENTICATED);
81+
LocalStore localStore = new LocalStore(persistence, queryEngine, User.UNAUTHENTICATED);
8382
RemoteStore remoteStore =
8483
new RemoteStore(callback, localStore, datastore, testQueue, connectivityMonitor);
8584

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import com.google.firebase.firestore.local.IndexBackfiller;
1818
import com.google.firebase.firestore.local.LocalSerializer;
19+
import com.google.firebase.firestore.local.LocalStore;
1920
import com.google.firebase.firestore.local.LruDelegate;
2021
import com.google.firebase.firestore.local.LruGarbageCollector;
2122
import com.google.firebase.firestore.local.Persistence;
@@ -35,7 +36,12 @@ protected Scheduler createGarbageCollectionScheduler(Configuration configuration
3536

3637
@Override
3738
protected IndexBackfiller createIndexBackfiller(Configuration configuration) {
38-
return new IndexBackfiller(getPersistence(), configuration.getAsyncQueue(), getLocalStore());
39+
LocalStore localStore = getLocalStore();
40+
return new IndexBackfiller(
41+
getPersistence(),
42+
configuration.getAsyncQueue(),
43+
localStore::getIndexManagerForCurrentUser,
44+
localStore::getLocalDocumentsForCurrentUser);
3945
}
4046

4147
@Override

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import androidx.annotation.Nullable;
1818
import androidx.annotation.VisibleForTesting;
19+
import com.google.common.base.Supplier;
1920
import com.google.firebase.firestore.model.Document;
2021
import com.google.firebase.firestore.model.DocumentKey;
2122
import com.google.firebase.firestore.model.FieldIndex.IndexOffset;
@@ -39,13 +40,19 @@ public class IndexBackfiller {
3940

4041
private final Scheduler scheduler;
4142
private final Persistence persistence;
42-
private final UserComponents components;
43+
private final Supplier<IndexManager> indexManagerOfCurrentUser;
44+
private final Supplier<LocalDocumentsView> localDocumentsViewOfCurrentUser;
4345
private int maxDocumentsToProcess = MAX_DOCUMENTS_TO_PROCESS;
4446

45-
public IndexBackfiller(Persistence persistence, AsyncQueue asyncQueue, UserComponents components) {
47+
public IndexBackfiller(
48+
Persistence persistence,
49+
AsyncQueue asyncQueue,
50+
Supplier<IndexManager> indexManagerOfCurrentUser,
51+
Supplier<LocalDocumentsView> localDocumentsViewOfCurrentUser) {
4652
this.persistence = persistence;
47-
this.components = components;
4853
this.scheduler = new Scheduler(asyncQueue);
54+
this.indexManagerOfCurrentUser = indexManagerOfCurrentUser;
55+
this.localDocumentsViewOfCurrentUser = localDocumentsViewOfCurrentUser;
4956
}
5057

5158
public class Scheduler implements com.google.firebase.firestore.local.Scheduler {
@@ -92,7 +99,7 @@ public int backfill() {
9299

93100
/** Writes index entries until the cap is reached. Returns the number of documents processed. */
94101
private int writeIndexEntries() {
95-
IndexManager indexManager = components.getIndexManager();
102+
IndexManager indexManager = indexManagerOfCurrentUser.get();
96103
Set<String> processedCollectionGroups = new HashSet<>();
97104
int documentsRemaining = maxDocumentsToProcess;
98105
while (documentsRemaining > 0) {
@@ -112,8 +119,8 @@ private int writeIndexEntries() {
112119
*/
113120
private int writeEntriesForCollectionGroup(
114121
String collectionGroup, int documentsRemainingUnderCap) {
115-
IndexManager indexManager = components.getIndexManager();
116-
LocalDocumentsView localDocumentsView = components.getLocalDocuments();
122+
IndexManager indexManager = indexManagerOfCurrentUser.get();
123+
LocalDocumentsView localDocumentsView = localDocumentsViewOfCurrentUser.get();
117124
// Use the earliest offset of all field indexes to query the local cache.
118125
IndexOffset existingOffset = indexManager.getMinOffset(collectionGroup);
119126

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
* in remoteDocumentCache or local mutations for the document). The view is computed by applying the
4949
* mutations in the MutationQueue to the RemoteDocumentCache.
5050
*/
51-
class LocalDocumentsView {
51+
public class LocalDocumentsView {
5252

5353
private final RemoteDocumentCache remoteDocumentCache;
5454
private final MutationQueue mutationQueue;

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
* <p>The LocalStore must be able to efficiently execute queries against its local cache of the
100100
* documents, to provide the initial set of results before any remote changes have been received.
101101
*/
102-
public final class LocalStore implements BundleCallback, UserComponents {
102+
public final class LocalStore implements BundleCallback {
103103
/**
104104
* The maximum time to leave a resume token buffered without writing it out. This value is
105105
* arbitrary: it's long enough to avoid several writes (possibly indefinitely if updates come more
@@ -192,13 +192,11 @@ private void startMutationQueue() {
192192
persistence.runTransaction("Start MutationQueue", () -> mutationQueue.start());
193193
}
194194

195-
@Override
196-
public IndexManager getIndexManager() {
195+
public IndexManager getIndexManagerForCurrentUser() {
197196
return indexManager;
198197
}
199198

200-
@Override
201-
public LocalDocumentsView getLocalDocuments() {
199+
public LocalDocumentsView getLocalDocumentsForCurrentUser() {
202200
return localDocuments;
203201
}
204202

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

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

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

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
import static com.google.firebase.firestore.testutil.TestUtil.version;
2929
import static junit.framework.TestCase.assertEquals;
3030
import static junit.framework.TestCase.assertTrue;
31-
import static org.mockito.Mockito.mock;
32-
import static org.mockito.Mockito.when;
3331

3432
import com.google.firebase.firestore.auth.User;
3533
import com.google.firebase.firestore.core.Query;
@@ -85,18 +83,9 @@ public void setUp() {
8583
persistence.getMutationQueue(User.UNAUTHENTICATED, indexManager),
8684
documentOverlayCache,
8785
indexManager);
88-
UserComponents components = new UserComponents() {
89-
@Override
90-
public IndexManager getIndexManager() {
91-
return indexManager;
92-
}
93-
94-
@Override
95-
public LocalDocumentsView getLocalDocuments() {
96-
return localDocumentsView;
97-
}
98-
};
99-
backfiller = new IndexBackfiller(persistence, new AsyncQueue(), components);
86+
backfiller =
87+
new IndexBackfiller(
88+
persistence, new AsyncQueue(), () -> indexManager, () -> localDocumentsView);
10089
}
10190

10291
@After

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import static com.google.firebase.firestore.testutil.TestUtil.deleteMutation;
2121
import static com.google.firebase.firestore.testutil.TestUtil.deletedDoc;
2222
import static com.google.firebase.firestore.testutil.TestUtil.doc;
23-
import static com.google.firebase.firestore.testutil.TestUtil.docMap;
2423
import static com.google.firebase.firestore.testutil.TestUtil.existenceFilterEvent;
2524
import static com.google.firebase.firestore.testutil.TestUtil.filter;
2625
import static com.google.firebase.firestore.testutil.TestUtil.key;
@@ -127,7 +126,12 @@ public void setUp() {
127126
queryEngine = new CountingQueryEngine(new QueryEngine());
128127
localStore = new LocalStore(localStorePersistence, queryEngine, User.UNAUTHENTICATED);
129128
localStore.start();
130-
indexBackfiller = new IndexBackfiller(localStorePersistence, new AsyncQueue(), localStore);
129+
indexBackfiller =
130+
new IndexBackfiller(
131+
localStorePersistence,
132+
new AsyncQueue(),
133+
localStore::getIndexManagerForCurrentUser,
134+
localStore::getLocalDocumentsForCurrentUser);
131135
}
132136

133137
@After

0 commit comments

Comments
 (0)