diff --git a/firebase-firestore/CHANGELOG.md b/firebase-firestore/CHANGELOG.md index 5f944dd015c..c10d8e74533 100644 --- a/firebase-firestore/CHANGELOG.md +++ b/firebase-firestore/CHANGELOG.md @@ -1,5 +1,6 @@ # Unreleased * [fixed] Implement equals method on Filter class. [#5210](//github.com/firebase/firebase-android-sdk/issues/5210) +* [feature] Add option to allow SDK create cache indexes automatically to improve query execution locally. [`db.getPersistentCacheIndexManager().enableIndexAutoCreation()`](//github.com/firebase/firebase-android-sdk/pull/4987) # 24.7.0 * [feature] Expose MultiDb support in API. [#4015](//github.com/firebase/firebase-android-sdk/issues/4015) diff --git a/firebase-firestore/api.txt b/firebase-firestore/api.txt index c61fc547913..e9c898700dc 100644 --- a/firebase-firestore/api.txt +++ b/firebase-firestore/api.txt @@ -189,6 +189,7 @@ package com.google.firebase.firestore { method @NonNull public static com.google.firebase.firestore.FirebaseFirestore getInstance(@NonNull String); method @NonNull public static com.google.firebase.firestore.FirebaseFirestore getInstance(@NonNull com.google.firebase.FirebaseApp, @NonNull String); method @NonNull public com.google.android.gms.tasks.Task getNamedQuery(@NonNull String); + method @Nullable public com.google.firebase.firestore.PersistentCacheIndexManager getPersistentCacheIndexManager(); method @NonNull public com.google.firebase.firestore.LoadBundleTask loadBundle(@NonNull java.io.InputStream); method @NonNull public com.google.firebase.firestore.LoadBundleTask loadBundle(@NonNull byte[]); method @NonNull public com.google.firebase.firestore.LoadBundleTask loadBundle(@NonNull java.nio.ByteBuffer); @@ -357,6 +358,12 @@ package com.google.firebase.firestore { method public void onProgress(@NonNull ProgressT); } + public final class PersistentCacheIndexManager { + method public void deleteAllIndexes(); + method public void disableIndexAutoCreation(); + method public void enableIndexAutoCreation(); + } + public final class PersistentCacheSettings implements com.google.firebase.firestore.LocalCacheSettings { method public long getSizeBytes(); method @NonNull public static com.google.firebase.firestore.PersistentCacheSettings.Builder newBuilder(); diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/FirebaseFirestore.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/FirebaseFirestore.java index 0a0593ac75f..5cb4cbec351 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/FirebaseFirestore.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/FirebaseFirestore.java @@ -23,7 +23,6 @@ import androidx.annotation.Keep; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.annotation.RestrictTo; import androidx.annotation.VisibleForTesting; import com.google.android.gms.tasks.Task; import com.google.android.gms.tasks.TaskCompletionSource; @@ -356,7 +355,11 @@ public FirebaseApp getApp() { * @param json The JSON format exported by the Firebase CLI. * @return A task that resolves once all indices are successfully configured. * @throws IllegalArgumentException if the JSON format is invalid + * @deprecated Instead of creating cache indexes manually, consider using {@link + * PersistentCacheIndexManager#enableIndexAutoCreation()} to let SDK decide whether to create + * cache indexes for queries running locally. */ + @Deprecated @PreviewApi @NonNull public Task setIndexConfiguration(@NonNull String json) { @@ -412,9 +415,6 @@ public Task setIndexConfiguration(@NonNull String json) { * @return The {@code PersistentCacheIndexManager} instance or null if local persistent storage is * not in use. */ - // TODO(csi): Remove the `hide` and scope annotations. - /** @hide */ - @RestrictTo(RestrictTo.Scope.LIBRARY) @Nullable public synchronized PersistentCacheIndexManager getPersistentCacheIndexManager() { ensureClientConfigured(); diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/PersistentCacheIndexManager.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/PersistentCacheIndexManager.java index f73b2332049..2980041b70e 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/PersistentCacheIndexManager.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/PersistentCacheIndexManager.java @@ -24,12 +24,11 @@ * *

To use, call {@link FirebaseFirestore#getPersistentCacheIndexManager()} to get an instance. */ -// TODO(csi): Remove the `hide` and scope annotations. -/** @hide */ -@RestrictTo(RestrictTo.Scope.LIBRARY) public final class PersistentCacheIndexManager { @NonNull private FirestoreClient client; + /** @hide */ + @RestrictTo(RestrictTo.Scope.LIBRARY) PersistentCacheIndexManager(FirestoreClient client) { this.client = client; } diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/local/QueryEngine.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/local/QueryEngine.java index 9c9a707e2d0..764a008919b 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/local/QueryEngine.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/local/QueryEngine.java @@ -146,12 +146,6 @@ private void createCacheIndexes(Query query, QueryContext context, int resultSiz "The SDK decides to create cache indexes for query: %s, as using cache indexes " + "may help improve performance.", query.toString()); - } else { - Logger.debug( - LOG_TAG, - "The SDK decides not to create cache indexes for this query: %s, as using cache " - + "indexes may not help improve performance.", - query.toString()); } }