-
Notifications
You must be signed in to change notification settings - Fork 616
Add option to allow SDK create cache indexes automatically to improve query execution locally #4987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 21 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
beeb296
Add counter
cherylEnkidu d0ea51c
address feedback 1
cherylEnkidu 4794dd7
add copyright
cherylEnkidu 67471cf
fix concurrency bug
cherylEnkidu 5d3d008
implement autoClientIndexing
cherylEnkidu 6afe360
Add tests and fix bugs for BuildTargetIndex
cherylEnkidu 28e9629
hide getter from public API
cherylEnkidu 2502cb5
move the flag from IndexManager to QueryEngine
cherylEnkidu 6d6eaec
Address feedback
cherylEnkidu 544de86
move auto index flag to runtime
cherylEnkidu 81b5c29
Support old way to enable persistent for PersistentCacheManager
cherylEnkidu 00b4ea1
Polish Tests
cherylEnkidu 0e71ee2
Add hide and copyright
cherylEnkidu fb9a561
clean up unused function
cherylEnkidu 31095b0
Rename PersistentCacheManager to PersistentCacheIndexManager
cherylEnkidu 5b56b0b
Remove unused QueryContext
cherylEnkidu 87e3ac1
Address feedbacks other than adding tests and comments
cherylEnkidu 32cfc69
Change the api to match the update
cherylEnkidu 8c8ae8c
Add tests
cherylEnkidu 39318da
Increase tests coverage
cherylEnkidu 14a6a71
Add comments
cherylEnkidu 39756f4
add configurable min documents to create indexes
cherylEnkidu 3f7a970
Address Denver's feedback
cherylEnkidu 48d649f
Address feedback
cherylEnkidu 6c6698e
address more feedbacks
cherylEnkidu 0336972
use the number getting from 100 ~ 1000 documents experiment
cherylEnkidu 46cfa2f
Address feedbacks
cherylEnkidu fb12477
improve debug log
cherylEnkidu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...se-firestore/src/main/java/com/google/firebase/firestore/PersistentCacheIndexManager.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2023 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.firebase.firestore; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.RestrictTo; | ||
import com.google.firebase.firestore.core.FirestoreClient; | ||
|
||
/** | ||
* A {@code PersistentCacheIndexManager} which you can config persistent cache indexes used for | ||
* local query execution. | ||
* | ||
* <p>To use, calling {@link FirebaseFirestore#getPersistentCacheIndexManager()} to get an instance. | ||
cherylEnkidu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
// TODO(csi): Remove the `hide` and scope annotations. | ||
/** @hide */ | ||
@RestrictTo(RestrictTo.Scope.LIBRARY) | ||
public class PersistentCacheIndexManager { | ||
cherylEnkidu marked this conversation as resolved.
Show resolved
Hide resolved
dconeybe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@NonNull private FirestoreClient client; | ||
|
||
@RestrictTo(RestrictTo.Scope.LIBRARY) | ||
public PersistentCacheIndexManager(FirestoreClient client) { | ||
dconeybe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.client = client; | ||
} | ||
|
||
/** | ||
* Enables SDK to create persistent cache indexes automatically for local query execution when SDK | ||
* believes cache indexes can help improves performance. | ||
* | ||
* <p>This feature is disabled by default. | ||
*/ | ||
public void enableIndexAutoCreation() { | ||
client.enableIndexAutoCreation(); | ||
} | ||
|
||
/** | ||
* Stops creating persistent cache indexes automatically for local query execution. The indexes | ||
* which have been created by calling {@link #enableIndexAutoCreation()} still take effect. | ||
*/ | ||
public void disableIndexAutoCreation() { | ||
client.disableIndexAutoCreation(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
firebase-firestore/src/main/java/com/google/firebase/firestore/local/QueryContext.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2023 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.firebase.firestore.local; | ||
|
||
/** A tracker to keep a record of important details during database local query execution. */ | ||
public class QueryContext { | ||
dconeybe marked this conversation as resolved.
Show resolved
Hide resolved
dconeybe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public QueryContext() {} | ||
dconeybe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** Counts the number of documents passed through during local query execution. */ | ||
private int documentReadCount = 0; | ||
|
||
public int getDocumentReadCount() { | ||
return documentReadCount; | ||
} | ||
|
||
public void increaseDocumentCount() { | ||
dconeybe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
documentReadCount++; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.