Skip to content

Commit fbd8e0e

Browse files
authored
Firestore: Release enablePersistentCacheIndexAutoCreation() and related functions (#7599)
1 parent c5b9b1f commit fbd8e0e

9 files changed

+213
-24
lines changed

.changeset/hip-cougars-float.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@firebase/firestore': minor
3+
'firebase': minor
4+
---
5+
6+
Add `enablePersistentCacheIndexAutoCreation()` function to enable automatic creation of local cache query indexes, which can improve performance of local query execution.

common/api-review/firestore.api.md

+22-5
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ export function connectFirestoreEmulator(firestore: Firestore, host: string, por
101101
mockUserToken?: EmulatorMockTokenOptions | string;
102102
}): void;
103103

104+
// @public
105+
export function deleteAllPersistentCacheIndexes(indexManager: PersistentCacheIndexManager): void;
106+
104107
// @public
105108
export function deleteDoc<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>): Promise<void>;
106109

@@ -110,6 +113,9 @@ export function deleteField(): FieldValue;
110113
// @public
111114
export function disableNetwork(firestore: Firestore): Promise<void>;
112115

116+
// @public
117+
export function disablePersistentCacheIndexAutoCreation(indexManager: PersistentCacheIndexManager): void;
118+
113119
// @public
114120
export function doc(firestore: Firestore, path: string, ...pathSegments: string[]): DocumentReference<DocumentData, DocumentData>;
115121

@@ -172,6 +178,9 @@ export function enableMultiTabIndexedDbPersistence(firestore: Firestore): Promis
172178
// @public
173179
export function enableNetwork(firestore: Firestore): Promise<void>;
174180

181+
// @public
182+
export function enablePersistentCacheIndexAutoCreation(indexManager: PersistentCacheIndexManager): void;
183+
175184
// @public
176185
export function endAt<AppModelType, DbModelType extends DocumentData>(snapshot: DocumentSnapshot<AppModelType, DbModelType>): QueryEndAtConstraint;
177186

@@ -286,25 +295,28 @@ export function getFirestore(): Firestore;
286295
// @beta
287296
export function getFirestore(app: FirebaseApp, databaseId: string): Firestore;
288297

298+
// @public
299+
export function getPersistentCacheIndexManager(firestore: Firestore): PersistentCacheIndexManager | null;
300+
289301
// @public
290302
export function increment(n: number): FieldValue;
291303

292-
// @beta
304+
// @beta @deprecated
293305
export interface Index {
294306
// (undocumented)
295307
[key: string]: unknown;
296308
readonly collectionGroup: string;
297309
readonly fields?: IndexField[];
298310
}
299311

300-
// @beta
312+
// @beta @deprecated
301313
export interface IndexConfiguration {
302314
// (undocumented)
303315
[key: string]: unknown;
304316
readonly indexes?: Index[];
305317
}
306318

307-
// @beta
319+
// @beta @deprecated
308320
export interface IndexField {
309321
// (undocumented)
310322
[key: string]: unknown;
@@ -457,6 +469,11 @@ export interface PersistenceSettings {
457469
forceOwnership?: boolean;
458470
}
459471

472+
// @public
473+
export class PersistentCacheIndexManager {
474+
readonly type: 'PersistentCacheIndexManager';
475+
}
476+
460477
// @public
461478
export interface PersistentCacheSettings {
462479
cacheSizeBytes?: number;
@@ -596,10 +613,10 @@ export function setDoc<AppModelType, DbModelType extends DocumentData>(reference
596613
// @public
597614
export function setDoc<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>, data: PartialWithFieldValue<AppModelType>, options: SetOptions): Promise<void>;
598615

599-
// @beta
616+
// @beta @deprecated
600617
export function setIndexConfiguration(firestore: Firestore, configuration: IndexConfiguration): Promise<void>;
601618

602-
// @beta
619+
// @beta @deprecated
603620
export function setIndexConfiguration(firestore: Firestore, json: string): Promise<void>;
604621

605622
// @public

docs-devsite/firestore_.index.md

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ https://github.com/firebase/firebase-js-sdk
1313
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
1414
>
1515
16+
> Warning: This API is now obsolete.
17+
>
18+
> Instead of creating cache indexes manually, consider using `enablePersistentCacheIndexAutoCreation()` to let the SDK decide whether to create cache indexes for queries running locally.
19+
>
20+
1621
The SDK definition of a Firestore index.
1722

1823
<b>Signature:</b>

docs-devsite/firestore_.indexconfiguration.md

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ https://github.com/firebase/firebase-js-sdk
1313
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
1414
>
1515
16+
> Warning: This API is now obsolete.
17+
>
18+
> Instead of creating cache indexes manually, consider using `enablePersistentCacheIndexAutoCreation()` to let the SDK decide whether to create cache indexes for queries running locally.
19+
>
20+
1621
A list of Firestore indexes to speed up local query execution.
1722

1823
See [JSON Format](https://firebase.google.com/docs/reference/firestore/indexes/#json_format) for a description of the format of the index definition.

docs-devsite/firestore_.indexfield.md

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ https://github.com/firebase/firebase-js-sdk
1313
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
1414
>
1515
16+
> Warning: This API is now obsolete.
17+
>
18+
> Instead of creating cache indexes manually, consider using `enablePersistentCacheIndexAutoCreation()` to let the SDK decide whether to create cache indexes for queries running locally.
19+
>
20+
1621
A single field element in an index configuration.
1722

1823
<b>Signature:</b>

docs-devsite/firestore_.md

+102
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ https://github.com/firebase/firebase-js-sdk
2929
| [enableIndexedDbPersistence(firestore, persistenceSettings)](./firestore_.md#enableindexeddbpersistence) | Attempts to enable persistent storage, if possible.<!-- -->Must be called before any other functions (other than [initializeFirestore()](./firestore_.md#initializefirestore)<!-- -->, [getFirestore()](./firestore_.md#getfirestore) or [clearIndexedDbPersistence()](./firestore_.md#clearindexeddbpersistence)<!-- -->.<!-- -->If this fails, <code>enableIndexedDbPersistence()</code> will reject the promise it returns. Note that even after this failure, the [Firestore](./firestore_.firestore.md#firestore_class) instance will remain usable, however offline persistence will be disabled.<!-- -->There are several reasons why this can fail, which can be identified by the <code>code</code> on the error.<!-- -->\* failed-precondition: The app is already open in another browser tab. \* unimplemented: The browser is incompatible with the offline persistence implementation.<!-- -->Persistence cannot be used in a Node.js environment. |
3030
| [enableMultiTabIndexedDbPersistence(firestore)](./firestore_.md#enablemultitabindexeddbpersistence) | Attempts to enable multi-tab persistent storage, if possible. If enabled across all tabs, all operations share access to local persistence, including shared execution of queries and latency-compensated local document updates across all connected instances.<!-- -->If this fails, <code>enableMultiTabIndexedDbPersistence()</code> will reject the promise it returns. Note that even after this failure, the [Firestore](./firestore_.firestore.md#firestore_class) instance will remain usable, however offline persistence will be disabled.<!-- -->There are several reasons why this can fail, which can be identified by the <code>code</code> on the error.<!-- -->\* failed-precondition: The app is already open in another browser tab and multi-tab is not enabled. \* unimplemented: The browser is incompatible with the offline persistence implementation. |
3131
| [enableNetwork(firestore)](./firestore_.md#enablenetwork) | Re-enables use of the network for this [Firestore](./firestore_.firestore.md#firestore_class) instance after a prior call to [disableNetwork()](./firestore_.md#disablenetwork)<!-- -->. |
32+
| [getPersistentCacheIndexManager(firestore)](./firestore_.md#getpersistentcacheindexmanager) | Returns the PersistentCache Index Manager used by the given <code>Firestore</code> object. The <code>PersistentCacheIndexManager</code> instance, or <code>null</code> if local persistent storage is not in use. |
3233
| [loadBundle(firestore, bundleData)](./firestore_.md#loadbundle) | Loads a Firestore bundle into the local cache. |
3334
| [namedQuery(firestore, name)](./firestore_.md#namedquery) | Reads a Firestore [Query](./firestore_.query.md#query_class) from local cache, identified by the given name.<!-- -->The named queries are packaged into bundles on the server side (along with resulting documents), and loaded to local cache using <code>loadBundle</code>. Once in local cache, use this method to extract a [Query](./firestore_.query.md#query_class) by name. |
3435
| [onSnapshotsInSync(firestore, observer)](./firestore_.md#onsnapshotsinsync) | Attaches a listener for a snapshots-in-sync event. The snapshots-in-sync event indicates that all listeners affected by a given change have fired, even if a single server-generated change affects multiple listeners.<!-- -->NOTE: The snapshots-in-sync event only indicates that listeners are in sync with each other, but does not relate to whether those snapshots are in sync with the server. Use SnapshotMetadata in the individual listeners to determine if a snapshot is from the cache or the server. |
@@ -59,6 +60,10 @@ https://github.com/firebase/firebase-js-sdk
5960
| [endBefore(fieldValues)](./firestore_.md#endbefore) | Creates a [QueryEndAtConstraint](./firestore_.queryendatconstraint.md#queryendatconstraint_class) that modifies the result set to end before the provided fields relative to the order of the query. The order of the field values must match the order of the order by clauses of the query. |
6061
| [startAfter(fieldValues)](./firestore_.md#startafter) | Creates a [QueryStartAtConstraint](./firestore_.querystartatconstraint.md#querystartatconstraint_class) that modifies the result set to start after the provided fields relative to the order of the query. The order of the field values must match the order of the order by clauses of the query. |
6162
| [startAt(fieldValues)](./firestore_.md#startat) | Creates a [QueryStartAtConstraint](./firestore_.querystartatconstraint.md#querystartatconstraint_class) that modifies the result set to start at the provided fields relative to the order of the query. The order of the field values must match the order of the order by clauses of the query. |
63+
| <b>function(indexManager...)</b> |
64+
| [deleteAllPersistentCacheIndexes(indexManager)](./firestore_.md#deleteallpersistentcacheindexes) | Removes all persistent cache indexes.<!-- -->Please note this function will also deletes indexes generated by <code>setIndexConfiguration()</code>, which is deprecated. |
65+
| [disablePersistentCacheIndexAutoCreation(indexManager)](./firestore_.md#disablepersistentcacheindexautocreation) | Stops creating persistent cache indexes automatically for local query execution. The indexes which have been created by calling <code>enablePersistentCacheIndexAutoCreation()</code> still take effect. |
66+
| [enablePersistentCacheIndexAutoCreation(indexManager)](./firestore_.md#enablepersistentcacheindexautocreation) | Enables the SDK to create persistent cache indexes automatically for local query execution when the SDK believes cache indexes can help improve performance.<!-- -->This feature is disabled by default. |
6267
| <b>function(left...)</b> |
6368
| [aggregateQuerySnapshotEqual(left, right)](./firestore_.md#aggregatequerysnapshotequal) | Compares two <code>AggregateQuerySnapshot</code> instances for equality.<!-- -->Two <code>AggregateQuerySnapshot</code> instances are considered "equal" if they have underlying queries that compare equal, and the same data. |
6469
| [queryEqual(left, right)](./firestore_.md#queryequal) | Returns true if the provided queries point to the same collection and apply the same constraints. |
@@ -130,6 +135,7 @@ https://github.com/firebase/firebase-js-sdk
130135
| [FirestoreError](./firestore_.firestoreerror.md#firestoreerror_class) | An error returned by a Firestore operation. |
131136
| [GeoPoint](./firestore_.geopoint.md#geopoint_class) | An immutable object representing a geographic location in Firestore. The location is represented as latitude/longitude pair.<!-- -->Latitude values are in the range of \[-90, 90\]. Longitude values are in the range of \[-180, 180\]. |
132137
| [LoadBundleTask](./firestore_.loadbundletask.md#loadbundletask_class) | Represents the task of loading a Firestore bundle. It provides progress of bundle loading, as well as task completion and error events.<!-- -->The API is compatible with <code>Promise&lt;LoadBundleTaskProgress&gt;</code>. |
138+
| [PersistentCacheIndexManager](./firestore_.persistentcacheindexmanager.md#persistentcacheindexmanager_class) | A <code>PersistentCacheIndexManager</code> for configuring persistent cache indexes used for local query execution.<!-- -->To use, call <code>getPersistentCacheIndexManager()</code> to get an instance. |
133139
| [Query](./firestore_.query.md#query_class) | A <code>Query</code> refers to a query which you can read or listen to. You can also construct refined <code>Query</code> objects by adding filters and ordering. |
134140
| [QueryCompositeFilterConstraint](./firestore_.querycompositefilterconstraint.md#querycompositefilterconstraint_class) | A <code>QueryCompositeFilterConstraint</code> is used to narrow the set of documents returned by a Firestore query by performing the logical OR or AND of multiple [QueryFieldFilterConstraint](./firestore_.queryfieldfilterconstraint.md#queryfieldfilterconstraint_class)<!-- -->s or [QueryCompositeFilterConstraint](./firestore_.querycompositefilterconstraint.md#querycompositefilterconstraint_class)<!-- -->s. <code>QueryCompositeFilterConstraint</code>s are created by invoking [or()](./firestore_.md#or) or [and()](./firestore_.md#and) and can then be passed to [query()](./firestore_.md#query) to create a new query instance that also contains the <code>QueryCompositeFilterConstraint</code>. |
135141
| [QueryConstraint](./firestore_.queryconstraint.md#queryconstraint_class) | A <code>QueryConstraint</code> is used to narrow the set of documents returned by a Firestore query. <code>QueryConstraint</code>s are created by invoking [where()](./firestore_.md#where)<!-- -->, [orderBy()](./firestore_.md#orderby)<!-- -->, [startAt()](./firestore_.md#startat)<!-- -->, [startAfter()](./firestore_.md#startafter)<!-- -->, [endBefore()](./firestore_.md#endbefore)<!-- -->, [endAt()](./firestore_.md#endat)<!-- -->, [limit()](./firestore_.md#limit)<!-- -->, [limitToLast()](./firestore_.md#limittolast) and can then be passed to [query()](./firestore_.md#query) to create a new query instance that also contains this <code>QueryConstraint</code>. |
@@ -526,6 +532,28 @@ Promise&lt;void&gt;
526532

527533
A `Promise` that is resolved once the network has been enabled.
528534

535+
## getPersistentCacheIndexManager()
536+
537+
Returns the PersistentCache Index Manager used by the given `Firestore` object.
538+
539+
The `PersistentCacheIndexManager` instance, or `null` if local persistent storage is not in use.
540+
541+
<b>Signature:</b>
542+
543+
```typescript
544+
export declare function getPersistentCacheIndexManager(firestore: Firestore): PersistentCacheIndexManager | null;
545+
```
546+
547+
### Parameters
548+
549+
| Parameter | Type | Description |
550+
| --- | --- | --- |
551+
| firestore | [Firestore](./firestore_.firestore.md#firestore_class) | |
552+
553+
<b>Returns:</b>
554+
555+
[PersistentCacheIndexManager](./firestore_.persistentcacheindexmanager.md#persistentcacheindexmanager_class) \| null
556+
529557
## loadBundle()
530558

531559
Loads a Firestore bundle into the local cache.
@@ -659,6 +687,11 @@ If the transaction completed successfully or was explicitly aborted (the `update
659687
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
660688
>
661689
690+
> Warning: This API is now obsolete.
691+
>
692+
> Instead of creating cache indexes manually, consider using `enablePersistentCacheIndexAutoCreation()` to let the SDK decide whether to create cache indexes for queries running locally.
693+
>
694+
662695
Configures indexing for local query execution. Any previous index configuration is overridden. The `Promise` resolves once the index configuration has been persisted.
663696

664697
The index entries themselves are created asynchronously. You can continue to use queries that require indexing even if the indices are not yet available. Query execution will automatically start using the index once the index entries have been written.
@@ -693,6 +726,11 @@ FirestoreError if the JSON format is invalid.
693726
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
694727
>
695728
729+
> Warning: This API is now obsolete.
730+
>
731+
> Instead of creating cache indexes manually, consider using `enablePersistentCacheIndexAutoCreation()` to let the SDK decide whether to create cache indexes for queries running locally.
732+
>
733+
696734
Configures indexing for local query execution. Any previous index configuration is overridden. The `Promise` resolves once the index configuration has been persisted.
697735

698736
The index entries themselves are created asynchronously. You can continue to use queries that require indexing even if the indices are not yet available. Query execution will automatically start using the index once the index entries have been written.
@@ -1090,6 +1128,70 @@ export declare function startAt(...fieldValues: unknown[]): QueryStartAtConstrai
10901128

10911129
A [QueryStartAtConstraint](./firestore_.querystartatconstraint.md#querystartatconstraint_class) to pass to `query()`<!-- -->.
10921130

1131+
## deleteAllPersistentCacheIndexes()
1132+
1133+
Removes all persistent cache indexes.
1134+
1135+
Please note this function will also deletes indexes generated by `setIndexConfiguration()`<!-- -->, which is deprecated.
1136+
1137+
<b>Signature:</b>
1138+
1139+
```typescript
1140+
export declare function deleteAllPersistentCacheIndexes(indexManager: PersistentCacheIndexManager): void;
1141+
```
1142+
1143+
### Parameters
1144+
1145+
| Parameter | Type | Description |
1146+
| --- | --- | --- |
1147+
| indexManager | [PersistentCacheIndexManager](./firestore_.persistentcacheindexmanager.md#persistentcacheindexmanager_class) | |
1148+
1149+
<b>Returns:</b>
1150+
1151+
void
1152+
1153+
## disablePersistentCacheIndexAutoCreation()
1154+
1155+
Stops creating persistent cache indexes automatically for local query execution. The indexes which have been created by calling `enablePersistentCacheIndexAutoCreation()` still take effect.
1156+
1157+
<b>Signature:</b>
1158+
1159+
```typescript
1160+
export declare function disablePersistentCacheIndexAutoCreation(indexManager: PersistentCacheIndexManager): void;
1161+
```
1162+
1163+
### Parameters
1164+
1165+
| Parameter | Type | Description |
1166+
| --- | --- | --- |
1167+
| indexManager | [PersistentCacheIndexManager](./firestore_.persistentcacheindexmanager.md#persistentcacheindexmanager_class) | |
1168+
1169+
<b>Returns:</b>
1170+
1171+
void
1172+
1173+
## enablePersistentCacheIndexAutoCreation()
1174+
1175+
Enables the SDK to create persistent cache indexes automatically for local query execution when the SDK believes cache indexes can help improve performance.
1176+
1177+
This feature is disabled by default.
1178+
1179+
<b>Signature:</b>
1180+
1181+
```typescript
1182+
export declare function enablePersistentCacheIndexAutoCreation(indexManager: PersistentCacheIndexManager): void;
1183+
```
1184+
1185+
### Parameters
1186+
1187+
| Parameter | Type | Description |
1188+
| --- | --- | --- |
1189+
| indexManager | [PersistentCacheIndexManager](./firestore_.persistentcacheindexmanager.md#persistentcacheindexmanager_class) | |
1190+
1191+
<b>Returns:</b>
1192+
1193+
void
1194+
10931195
## aggregateQuerySnapshotEqual()
10941196

10951197
Compares two `AggregateQuerySnapshot` instances for equality.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Project: /docs/reference/js/_project.yaml
2+
Book: /docs/reference/_book.yaml
3+
page_type: reference
4+
5+
{% comment %}
6+
DO NOT EDIT THIS FILE!
7+
This is generated by the JS SDK team, and any local changes will be
8+
overwritten. Changes should be made in the source code at
9+
https://github.com/firebase/firebase-js-sdk
10+
{% endcomment %}
11+
12+
# PersistentCacheIndexManager class
13+
A `PersistentCacheIndexManager` for configuring persistent cache indexes used for local query execution.
14+
15+
To use, call `getPersistentCacheIndexManager()` to get an instance.
16+
17+
<b>Signature:</b>
18+
19+
```typescript
20+
export declare class PersistentCacheIndexManager
21+
```
22+
23+
## Properties
24+
25+
| Property | Modifiers | Type | Description |
26+
| --- | --- | --- | --- |
27+
| [type](./firestore_.persistentcacheindexmanager.md#persistentcacheindexmanagertype) | | 'PersistentCacheIndexManager' | A type string to uniquely identify instances of this class. |
28+
29+
## PersistentCacheIndexManager.type
30+
31+
A type string to uniquely identify instances of this class.
32+
33+
<b>Signature:</b>
34+
35+
```typescript
36+
readonly type: 'PersistentCacheIndexManager';
37+
```

0 commit comments

Comments
 (0)