Skip to content

Commit 9e2f1c4

Browse files
authored
Merge branch 'master' into davidmotson.add_lg_publication_check
2 parents 4ca1f3e + 3d3eeaf commit 9e2f1c4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+978
-65
lines changed

.github/workflows/api-information.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
if: github.event.pull_request.head.repo.full_name == github.repository
88
runs-on: ubuntu-latest
99
steps:
10-
- uses: actions/checkout@v3
10+
- uses: actions/checkout@v3.5.3
1111
with:
1212
fetch-depth: 2
1313
submodules: true

.github/workflows/build-release-artifacts.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
env:
1414
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1515
steps:
16-
- uses: actions/checkout@v3
16+
- uses: actions/checkout@v3.5.3
1717

1818
- name: Set up JDK 11
1919
uses: actions/setup-java@v3

.github/workflows/build-src-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
build-src-check:
1414
runs-on: ubuntu-22.04
1515
steps:
16-
- uses: actions/checkout@v3.0.2
16+
- uses: actions/checkout@v3.5.3
1717
- name: Set up JDK 11
1818
uses: actions/setup-java@v3
1919
with:

.github/workflows/changelog.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
env:
1414
BUNDLE_GEMFILE: ./ci/danger/Gemfile
1515
steps:
16-
- uses: actions/checkout@v3
16+
- uses: actions/checkout@v3.5.3
1717
with:
1818
fetch-depth: 100
1919
submodules: true

.github/workflows/check-head-dependencies.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
check-head-dependencies:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v3
13+
- uses: actions/checkout@v3.5.3
1414

1515
- name: Perform gradle build
1616
run: |

.github/workflows/ci_tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
outputs:
1717
modules: ${{ steps.changed-modules.outputs.modules }}
1818
steps:
19-
- uses: actions/checkout@v3.0.2
19+
- uses: actions/checkout@v3.5.3
2020
with:
2121
fetch-depth: 2
2222
submodules: true
@@ -44,7 +44,7 @@ jobs:
4444
module: ${{ fromJSON(needs.determine_changed.outputs.modules) }}
4545

4646
steps:
47-
- uses: actions/checkout@v3.0.2
47+
- uses: actions/checkout@v3.5.3
4848
with:
4949
fetch-depth: 2
5050
submodules: true
@@ -100,7 +100,7 @@ jobs:
100100
module: ${{ fromJSON(needs.determine_changed.outputs.modules) }}
101101

102102
steps:
103-
- uses: actions/checkout@v3.0.2
103+
- uses: actions/checkout@v3.5.3
104104
with:
105105
fetch-depth: 2
106106
submodules: true

.github/workflows/create_releases.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
create-pull-request:
2727
runs-on: ubuntu-latest
2828
steps:
29-
- uses: actions/checkout@v3
29+
- uses: actions/checkout@v3.5.3
3030
with:
3131
fetch-depth: 0
3232

.github/workflows/diff-javadoc.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
run: mkdir ~/diff
1414

1515
- name: Checkout PR branch
16-
uses: actions/checkout@v3
16+
uses: actions/checkout@v3.5.3
1717
with:
1818
fetch-depth: 2
1919
submodules: true
@@ -32,7 +32,7 @@ jobs:
3232
run: mv build ~/diff/modified
3333

3434
- name: Checkout master
35-
uses: actions/checkout@v3
35+
uses: actions/checkout@v3.5.3
3636
with:
3737
ref: ${{ github.base_ref }}
3838

.github/workflows/fireci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
name: "fireci tests"
1616
runs-on: ubuntu-22.04
1717
steps:
18-
- uses: actions/checkout@v3.0.2
18+
- uses: actions/checkout@v3.5.3
1919
- uses: actions/setup-python@v2
2020
with:
2121
python-version: '3.8'

.github/workflows/fireperf-e2e.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ jobs:
2020
environment: [ prod, autopush ]
2121
steps:
2222
- name: Checkout firebase-android-sdk
23-
uses: actions/checkout@v3
23+
uses: actions/checkout@v3.5.3
2424
- name: Checkout firebase-android-buildtools
25-
uses: actions/checkout@v3
25+
uses: actions/checkout@v3.5.3
2626
with:
2727
repository: FirebasePrivate/firebase-android-buildtools
2828
token: ${{ secrets.GOOGLE_OSS_BOT_TOKEN }}

.github/workflows/health-metrics.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
&& github.event.pull_request.head.repo.full_name == github.repository)
2525
runs-on: ubuntu-latest
2626
steps:
27-
- uses: actions/checkout@v3
27+
- uses: actions/checkout@v3.5.3
2828
with:
2929
fetch-depth: 2
3030
submodules: true
@@ -59,7 +59,7 @@ jobs:
5959
&& github.event.pull_request.head.repo.full_name == github.repository)
6060
runs-on: ubuntu-latest
6161
steps:
62-
- uses: actions/checkout@v3
62+
- uses: actions/checkout@v3.5.3
6363
with:
6464
fetch-depth: 2
6565
submodules: true
@@ -95,7 +95,7 @@ jobs:
9595
&& github.event.pull_request.base.ref == 'master')
9696
runs-on: ubuntu-latest
9797
steps:
98-
- uses: actions/checkout@v3
98+
- uses: actions/checkout@v3.5.3
9999
with:
100100
fetch-depth: 2
101101
submodules: true

.github/workflows/jekyll-gh-pages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
runs-on: ubuntu-latest
3232
steps:
3333
- name: Checkout
34-
uses: actions/checkout@v3
34+
uses: actions/checkout@v3.5.3
3535
- name: Setup Pages
3636
uses: actions/configure-pages@v2
3737
- name: Build with Jekyll

.github/workflows/make-bom.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
uses: actions/setup-python@v4
1212
with:
1313
python-version: '3.10'
14-
- uses: actions/checkout@v3.0.2
14+
- uses: actions/checkout@v3.5.3
1515
- name: Set up JDK 11
1616
uses: actions/setup-java@v3
1717
with:

.github/workflows/private-mirror-sync.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
if: github.repository == 'firebase/firebase-android-sdk'
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: actions/checkout@v3
17+
- uses: actions/checkout@v3.5.3
1818
with:
1919
fetch-depth: 0
2020
submodules: true

.github/workflows/release-note-changes.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
build:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v3
12+
- uses: actions/checkout@v3.5.3
1313
with:
1414
fetch-depth: 0
1515

.github/workflows/scorecards.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232

3333
steps:
3434
- name: "Checkout code"
35-
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
35+
uses: actions/checkout@v3.5.3
3636
with:
3737
persist-credentials: false
3838

.github/workflows/semver-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
semver-check:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v3
13+
- uses: actions/checkout@v3.5.3
1414

1515
- name: Perform gradle build
1616
run: |

.github/workflows/sessions-e2e.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818

1919
steps:
2020
- name: Checkout firebase-sessions
21-
uses: actions/checkout@v3
21+
uses: actions/checkout@v3.5.3
2222

2323
- name: set up JDK 11
2424
uses: actions/setup-java@v3

.github/workflows/smoke-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
if: github.event.pull_request.head.repo.full_name == github.repository
88
runs-on: ubuntu-latest
99
steps:
10-
- uses: actions/checkout@v3
10+
- uses: actions/checkout@v3.5.3
1111
with:
1212
fetch-depth: 2
1313
submodules: true

.github/workflows/update-cpp-sdk-on-release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
outputs:
2424
released_version_changed: ${{ steps.check_version.outputs.released_version_changed }}
2525
steps:
26-
- uses: actions/checkout@v2.3.1
26+
- uses: actions/checkout@v3.5.3
2727
with:
2828
# Check out the actual head commit, not any merge commit.
2929
ref: ${{ github.sha }}
@@ -56,7 +56,7 @@ jobs:
5656
python-version: 3.7
5757

5858
- name: Check out firebase-cpp-sdk
59-
uses: actions/checkout@v2.3.1
59+
uses: actions/checkout@v3.5.3
6060
with:
6161
repository: firebase/firebase-cpp-sdk
6262
ref: main

.github/workflows/validate-dependencies.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
build-artifacts:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v3
13+
- uses: actions/checkout@v3.5.3
1414

1515
- name: Perform gradle build
1616
run: |

firebase-firestore/src/androidTest/java/com/google/firebase/firestore/IndexingTest.java

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@
1414

1515
package com.google.firebase.firestore;
1616

17+
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testCollectionWithDocs;
1718
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testFirestore;
19+
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.waitFor;
20+
import static com.google.firebase.firestore.testutil.TestUtil.assertDoesNotThrow;
21+
import static com.google.firebase.firestore.testutil.TestUtil.expectError;
22+
import static com.google.firebase.firestore.testutil.TestUtil.map;
23+
import static org.junit.Assert.assertEquals;
1824

1925
import androidx.test.ext.junit.runners.AndroidJUnit4;
2026
import com.google.android.gms.tasks.Task;
@@ -101,4 +107,73 @@ public void testBadIndexDoesNotCrashClient() {
101107
+ " \"fieldOverrides\": []\n"
102108
+ "}"));
103109
}
110+
111+
@Test
112+
public void testAutoIndexCreationSetSuccessfully() {
113+
// Use persistent disk cache (default)
114+
FirebaseFirestore db = testFirestore();
115+
FirebaseFirestoreSettings settings =
116+
new FirebaseFirestoreSettings.Builder(db.getFirestoreSettings())
117+
.setLocalCacheSettings(PersistentCacheSettings.newBuilder().build())
118+
.build();
119+
db.setFirestoreSettings(settings);
120+
121+
CollectionReference collection =
122+
testCollectionWithDocs(
123+
map(
124+
"a", map("match", true),
125+
"b", map("match", false),
126+
"c", map("match", false)));
127+
QuerySnapshot results = waitFor(collection.whereEqualTo("match", true).get());
128+
assertEquals(1, results.size());
129+
130+
assertDoesNotThrow(() -> db.getPersistentCacheIndexManager().enableIndexAutoCreation());
131+
132+
results = waitFor(collection.whereEqualTo("match", true).get());
133+
assertEquals(1, results.size());
134+
135+
assertDoesNotThrow(() -> db.getPersistentCacheIndexManager().disableIndexAutoCreation());
136+
137+
results = waitFor(collection.whereEqualTo("match", true).get());
138+
assertEquals(1, results.size());
139+
}
140+
141+
@Test
142+
public void testAutoIndexCreationSetSuccessfullyUsingDefault() {
143+
// Use persistent disk cache (default)
144+
FirebaseFirestore db = testFirestore();
145+
146+
CollectionReference collection =
147+
testCollectionWithDocs(
148+
map(
149+
"a", map("match", true),
150+
"b", map("match", false),
151+
"c", map("match", false)));
152+
QuerySnapshot results = waitFor(collection.whereEqualTo("match", true).get());
153+
assertEquals(1, results.size());
154+
155+
assertDoesNotThrow(() -> db.getPersistentCacheIndexManager().enableIndexAutoCreation());
156+
157+
results = waitFor(collection.whereEqualTo("match", true).get());
158+
assertEquals(1, results.size());
159+
160+
assertDoesNotThrow(() -> db.getPersistentCacheIndexManager().disableIndexAutoCreation());
161+
162+
results = waitFor(collection.whereEqualTo("match", true).get());
163+
assertEquals(1, results.size());
164+
}
165+
166+
@Test
167+
public void testAutoIndexCreationAfterFailsTermination() {
168+
FirebaseFirestore db = testFirestore();
169+
waitFor(db.terminate());
170+
171+
expectError(
172+
() -> db.getPersistentCacheIndexManager().enableIndexAutoCreation(),
173+
"The client has already been terminated");
174+
175+
expectError(
176+
() -> db.getPersistentCacheIndexManager().disableIndexAutoCreation(),
177+
"The client has already been terminated");
178+
}
104179
}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import androidx.annotation.Keep;
2424
import androidx.annotation.NonNull;
2525
import androidx.annotation.Nullable;
26+
import androidx.annotation.RestrictTo;
2627
import androidx.annotation.VisibleForTesting;
2728
import com.google.android.gms.tasks.Task;
2829
import com.google.android.gms.tasks.TaskCompletionSource;
@@ -104,6 +105,8 @@ public interface InstanceRegistry {
104105
private volatile FirestoreClient client;
105106
private final GrpcMetadataProvider metadataProvider;
106107

108+
@Nullable private PersistentCacheIndexManager persistentCacheIndexManager;
109+
107110
@NonNull
108111
private static FirebaseApp getDefaultFirebaseApp() {
109112
FirebaseApp app = FirebaseApp.getInstance();
@@ -403,6 +406,26 @@ public Task<Void> setIndexConfiguration(@NonNull String json) {
403406
return client.configureFieldIndexes(parsedIndexes);
404407
}
405408

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+
*/
415+
// TODO(csi): Remove the `hide` and scope annotations.
416+
/** @hide */
417+
@RestrictTo(RestrictTo.Scope.LIBRARY)
418+
@Nullable
419+
public synchronized PersistentCacheIndexManager getPersistentCacheIndexManager() {
420+
ensureClientConfigured();
421+
if (persistentCacheIndexManager == null
422+
&& (settings.isPersistenceEnabled()
423+
|| settings.getCacheSettings() instanceof PersistentCacheSettings)) {
424+
persistentCacheIndexManager = new PersistentCacheIndexManager(client);
425+
}
426+
return persistentCacheIndexManager;
427+
}
428+
406429
/**
407430
* Gets a {@code CollectionReference} instance that refers to the collection at the specified path
408431
* within the database.

0 commit comments

Comments
 (0)