From 52bbf211c342f450a40698ced78af64a219a39d8 Mon Sep 17 00:00:00 2001 From: cherylEnkidu Date: Thu, 17 Aug 2023 14:57:03 -0400 Subject: [PATCH 1/3] Public Auto Persistent Index Creation API --- firebase-firestore/CHANGELOG.md | 1 + firebase-firestore/api.txt | 7 +++++++ .../com/google/firebase/firestore/FirebaseFirestore.java | 8 ++++---- .../firebase/firestore/PersistentCacheIndexManager.java | 5 ++--- 4 files changed, 14 insertions(+), 7 deletions(-) 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..8223fac3c5c 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 cache + * indexed should be created for query 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; } From f49555c0b8e9d87bfab76623e23c944e5902c374 Mon Sep 17 00:00:00 2001 From: cherylEnkidu Date: Mon, 21 Aug 2023 15:51:29 -0400 Subject: [PATCH 2/3] remove redundant error message --- .../com/google/firebase/firestore/local/QueryEngine.java | 6 ------ 1 file changed, 6 deletions(-) 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()); } } From b49664d8e68b927fce6268d14b5fbca5c5aa7bb8 Mon Sep 17 00:00:00 2001 From: cherylEnkidu Date: Mon, 21 Aug 2023 16:11:08 -0400 Subject: [PATCH 3/3] Fix grammar error --- .../java/com/google/firebase/firestore/FirebaseFirestore.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 8223fac3c5c..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 @@ -356,8 +356,8 @@ public FirebaseApp getApp() { * @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 cache - * indexed should be created for query running locally. + * PersistentCacheIndexManager#enableIndexAutoCreation()} to let SDK decide whether to create + * cache indexes for queries running locally. */ @Deprecated @PreviewApi