Skip to content

Commit db08413

Browse files
author
Brian Chen
committed
resolve comments round 2
1 parent b92e273 commit db08413

File tree

4 files changed

+28
-23
lines changed

4 files changed

+28
-23
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public final class FirestoreClient {
7676
// LRU-related
7777
@Nullable private Scheduler gcScheduler;
7878

79-
@Nullable private Scheduler indexScheduler;
79+
@Nullable private Scheduler indexBackfillScheduler;
8080

8181
public FirestoreClient(
8282
final Context context,
@@ -146,8 +146,8 @@ public Task<Void> terminate() {
146146
gcScheduler.stop();
147147
}
148148

149-
if (indexScheduler != null && Persistence.INDEXING_SUPPORT_ENABLED) {
150-
indexScheduler.stop();
149+
if (indexBackfillScheduler != null) {
150+
indexBackfillScheduler.stop();
151151
}
152152
});
153153
}
@@ -262,7 +262,6 @@ private void initialize(Context context, User user, FirebaseFirestoreSettings se
262262
provider.initialize(configuration);
263263
persistence = provider.getPersistence();
264264
gcScheduler = provider.getGarbageCollectionScheduler();
265-
indexScheduler = provider.getIndexBackfillScheduler();
266265
localStore = provider.getLocalStore();
267266
remoteStore = provider.getRemoteStore();
268267
syncEngine = provider.getSyncEngine();
@@ -272,8 +271,10 @@ private void initialize(Context context, User user, FirebaseFirestoreSettings se
272271
gcScheduler.start();
273272
}
274273

275-
if (indexScheduler != null && Persistence.INDEXING_SUPPORT_ENABLED) {
276-
indexScheduler.start();
274+
if (Persistence.INDEXING_SUPPORT_ENABLED && settings.isPersistenceEnabled()) {
275+
indexBackfillScheduler = provider.getIndexBackfillScheduler();
276+
hardAssert(indexBackfillScheduler != null, "Index backfill scheduler should not be null.");
277+
indexBackfillScheduler.start();
277278
}
278279
}
279280

firebase-firestore/src/main/java/com/google/firebase/firestore/index/IndexEntry.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* Represents an index entry saved by the SDK in the local storage. Temporary placeholder, since
1919
* we'll probably serialize the indexValue right away rather than store it.
2020
*/
21+
// TODO(indexing)
2122
public class IndexEntry {
2223
private final int indexId;
2324
private final byte[] indexValue;

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
import com.google.firebase.firestore.util.AsyncQueue;
2121
import java.util.concurrent.TimeUnit;
2222

23-
/**
24-
* Implements the steps for backfilling indexes.
25-
*/
23+
/** Implements the steps for backfilling indexes. */
2624
public class IndexBackfiller {
2725
/** How long we wait to try running index backfill after SDK initialization. */
2826
private static final long INITIAL_BACKFILL_DELAY_MS = TimeUnit.SECONDS.toMillis(15);
@@ -105,14 +103,15 @@ public BackfillScheduler newScheduler(AsyncQueue asyncQueue, LocalStore localSto
105103
return new BackfillScheduler(asyncQueue, localStore);
106104
}
107105

108-
// TODO: Figure out which index entries to backfill.
106+
// TODO(indexing): Figure out which index entries to backfill.
109107
public Results backfill() {
110108
int numIndexesWritten = 0;
111109
int numIndexesRemoved = 0;
112110
return new Results(/* hasRun= */ true, numIndexesWritten, numIndexesRemoved);
113111
}
114112

115-
public void addIndexEntry(IndexEntry entry) {
113+
@VisibleForTesting
114+
void addIndexEntry(IndexEntry entry) {
116115
persistence.execute(
117116
"INSERT OR IGNORE INTO index_entries ("
118117
+ "index_id, "
@@ -125,7 +124,8 @@ public void addIndexEntry(IndexEntry entry) {
125124
entry.getDocumentId());
126125
}
127126

128-
public void removeIndexEntry(int indexId, String uid, String documentId) {
127+
@VisibleForTesting
128+
void removeIndexEntry(int indexId, String uid, String documentId) {
129129
persistence.execute(
130130
"DELETE FROM index_entries "
131131
+ "WHERE index_id = ? "
@@ -139,7 +139,7 @@ public void removeIndexEntry(int indexId, String uid, String documentId) {
139139

140140
@Nullable
141141
@VisibleForTesting
142-
public IndexEntry getIndexEntry(int indexId) {
142+
IndexEntry getIndexEntry(int indexId) {
143143
return persistence
144144
.query("SELECT index_value, uid, document_id FROM index_entries WHERE index_id = ?")
145145
.binding(indexId)

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public static void afterClass() {
5454
@Before
5555
public void setUp() {
5656
persistence = PersistenceTestHelpers.createSQLitePersistence();
57-
;
5857
backfiller = persistence.getIndexBackfiller();
5958
}
6059

@@ -67,15 +66,19 @@ public void tearDown() {
6766
public void addAndRemoveIndexEntry() {
6867
IndexEntry testEntry =
6968
new IndexEntry(1, "TEST_BLOB".getBytes(), "sample-uid", "sample-documentId");
70-
backfiller.addIndexEntry(testEntry);
71-
IndexEntry entry = backfiller.getIndexEntry(1);
72-
assertNotNull(entry);
73-
assertEquals("TEST_BLOB", new String(entry.getIndexValue()));
74-
assertEquals("sample-documentId", entry.getDocumentId());
75-
assertEquals("sample-uid", entry.getUid());
69+
persistence.runTransaction(
70+
"testAddAndRemoveIndexEntry",
71+
() -> {
72+
backfiller.addIndexEntry(testEntry);
73+
IndexEntry entry = backfiller.getIndexEntry(1);
74+
assertNotNull(entry);
75+
assertEquals("TEST_BLOB", new String(entry.getIndexValue()));
76+
assertEquals("sample-documentId", entry.getDocumentId());
77+
assertEquals("sample-uid", entry.getUid());
7678

77-
backfiller.removeIndexEntry(1, "sample-uid", "sample-documentId");
78-
entry = backfiller.getIndexEntry(1);
79-
assertNull(entry);
79+
backfiller.removeIndexEntry(1, "sample-uid", "sample-documentId");
80+
entry = backfiller.getIndexEntry(1);
81+
assertNull(entry);
82+
});
8083
}
8184
}

0 commit comments

Comments
 (0)