Skip to content

Commit 14a6a71

Browse files
committed
Add comments
1 parent 39318da commit 14a6a71

File tree

10 files changed

+54
-5
lines changed

10 files changed

+54
-5
lines changed

firebase-firestore/src/main/java/com/google/firebase/firestore/FirebaseFirestore.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,12 @@ public Task<Void> setIndexConfiguration(@NonNull String json) {
406406
return client.configureFieldIndexes(parsedIndexes);
407407
}
408408

409+
/**
410+
* Returns the PersistentCache Index Manager used by this {@code FirebaseFirestore} object.
411+
*
412+
* @return The {@code PersistentCacheIndexManager} instance or null if local persistent storage is
413+
* not in use.
414+
*/
409415
// TODO(csi): Remove the `hide` and scope annotations.
410416
/** @hide */
411417
@RestrictTo(RestrictTo.Scope.LIBRARY)

firebase-firestore/src/main/java/com/google/firebase/firestore/PersistentCacheIndexManager.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
import androidx.annotation.RestrictTo;
1919
import com.google.firebase.firestore.core.FirestoreClient;
2020

21+
/**
22+
* A {@code PersistentCacheIndexManager} which you can config persistent cache indexes used for
23+
* local query execution.
24+
*
25+
* <p>To use, calling {@link FirebaseFirestore#getPersistentCacheIndexManager()} to get an instance.
26+
*/
2127
// TODO(csi): Remove the `hide` and scope annotations.
2228
/** @hide */
2329
@RestrictTo(RestrictTo.Scope.LIBRARY)
@@ -29,10 +35,20 @@ public PersistentCacheIndexManager(FirestoreClient client) {
2935
this.client = client;
3036
}
3137

38+
/**
39+
* Enables SDK to create persistent cache indexes automatically for local query execution when SDK
40+
* believes cache indexes can help improves performance.
41+
*
42+
* <p>This feature is disabled by default.
43+
*/
3244
public void enableIndexAutoCreation() {
3345
client.enableIndexAutoCreation();
3446
}
3547

48+
/**
49+
* Stops creating persistent cache indexes automatically for local query execution. The indexes
50+
* which have been created by calling {@link #enableIndexAutoCreation()} still take effect.
51+
*/
3652
public void disableIndexAutoCreation() {
3753
client.disableIndexAutoCreation();
3854
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ enum IndexType {
7878
/** Removes the given field index and deletes all index values. */
7979
void deleteFieldIndex(FieldIndex index);
8080

81+
/** Creates a full matched field index which serves the given target. */
8182
void createTargetIndices(Target target);
8283

8384
/**

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ void recalculateAndSaveOverlays(Set<DocumentKey> documentKeys) {
258258
*
259259
* @param query The query to match documents against.
260260
* @param offset Read time and key to start scanning by (exclusive).
261+
* @param context A optional tracker to keep a record of important details during database local
262+
* query execution.
261263
*/
262264
ImmutableSortedMap<DocumentKey, Document> getDocumentsMatchingQuery(
263265
Query query, IndexOffset offset, @Nullable QueryContext context) {
@@ -271,6 +273,12 @@ ImmutableSortedMap<DocumentKey, Document> getDocumentsMatchingQuery(
271273
}
272274
}
273275

276+
/**
277+
* Performs a query against the local view of all documents.
278+
*
279+
* @param query The query to match documents against.
280+
* @param offset Read time and key to start scanning by (exclusive).
281+
*/
274282
ImmutableSortedMap<DocumentKey, Document> getDocumentsMatchingQuery(
275283
Query query, IndexOffset offset) {
276284
return getDocumentsMatchingQuery(query, offset, null);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414

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

17+
/** A tracker to keep a record of important details during database local query execution. */
1718
public class QueryContext {
1819
public QueryContext() {}
1920

21+
/** Counts the number of documents passed through during local query execution. */
2022
private int documentReadCount = 0;
2123

2224
public int getDocumentReadCount() {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ public ImmutableSortedMap<DocumentKey, Document> getDocumentsMatchingQuery(
105105
return result;
106106
}
107107

108+
/**
109+
* Decides whether SDK should create a full matched field index for this query based on query
110+
* context and query result size.
111+
*/
108112
// TODO(csi): Auto experiment data.
109113
private void CreateCacheIndexes(Query query, QueryContext context, int resultSize) {
110114
String decisionStr = "";

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ interface RemoteDocumentCache {
9191
Map<DocumentKey, MutableDocument> getDocumentsMatchingQuery(
9292
Query query, IndexOffset offset, @Nonnull Set<DocumentKey> mutatedKeys);
9393

94+
/**
95+
* Returns the documents that match the given query.
96+
*
97+
* @param query The query to match against remote documents.
98+
* @param offset The read time and document key to start scanning at (exclusive).
99+
* @param mutatedKeys The keys of documents who have mutations attached, they should be read
100+
* regardless whether they match the given query.
101+
* @param context A optional tracker to keep a record of important details during database local
102+
* query execution.
103+
* @return A newly created map with the set of documents in the collection.
104+
*/
94105
Map<DocumentKey, MutableDocument> getDocumentsMatchingQuery(
95106
Query query,
96107
IndexOffset offset,

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,7 @@ public Map<DocumentKey, MutableDocument> getAll(Iterable<DocumentKey> documentKe
140140
while (longQuery.hasMoreSubqueries()) {
141141
longQuery
142142
.performNextSubquery()
143-
.forEach(
144-
row -> {
145-
processRowInBackground(backgroundQueue, results, row, /*filter*/ null);
146-
});
143+
.forEach(row -> processRowInBackground(backgroundQueue, results, row, /*filter*/ null));
147144
}
148145
backgroundQueue.drain();
149146
return results;
@@ -226,6 +223,7 @@ private Map<DocumentKey, MutableDocument> getAll(
226223
row -> {
227224
processRowInBackground(backgroundQueue, results, row, filter);
228225
if (context != null) {
226+
// Increases the counter by 1 for every document processed.
229227
context.increaseDocumentCount();
230228
}
231229
});

firebase-firestore/src/main/java/com/google/firebase/firestore/model/TargetIndexMatcher.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,10 @@ public boolean servedByIndex(FieldIndex index) {
192192
return true;
193193
}
194194

195+
/** Returns a full matched field index for this target. */
195196
public FieldIndex BuildTargetIndex() {
197+
// We want to make sure only one segment created for one field. For example, in case like
198+
// a == 3 and a > 2, index, a ASCENDING, will only be created once.
196199
Set<FieldPath> uniqueFields = new HashSet<>();
197200
List<FieldIndex.Segment> segments = new ArrayList<>();
198201

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public Map<DocumentKey, MutableDocument> getAll(
180180

181181
@Override
182182
public Map<DocumentKey, MutableDocument> getDocumentsMatchingQuery(
183-
Query query, IndexOffset offset, Set<DocumentKey> mutatedKeys) {
183+
Query query, IndexOffset offset, @NonNull Set<DocumentKey> mutatedKeys) {
184184
return getDocumentsMatchingQuery(query, offset, mutatedKeys, null);
185185
}
186186

0 commit comments

Comments
 (0)