Skip to content

Commit be4b42b

Browse files
feat: setIndexConfigurationFromJSON() API. Allow users to pass JSON string (#10029)
* feat: `setIndexConfigurationFromJSON()` API * analyse issue
1 parent 3f5ca80 commit be4b42b

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

packages/cloud_firestore/cloud_firestore/example/integration_test/instance_e2e.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'dart:async';
6+
import 'dart:convert';
67

78
import 'package:flutter/foundation.dart';
89
import 'package:flutter_test/flutter_test.dart';
@@ -229,6 +230,30 @@ void runInstanceTests() {
229230
fieldOverrides: [fieldOverride1, fieldOverride2],
230231
);
231232
});
233+
234+
test('setIndexConfigurationFromJSON()', () async {
235+
final json = jsonEncode({
236+
'indexes': [
237+
{
238+
'collectionGroup': 'posts',
239+
'queryScope': 'COLLECTION',
240+
'fields': [
241+
{'fieldPath': 'author', 'arrayConfig': 'CONTAINS'},
242+
{'fieldPath': 'timestamp', 'order': 'DESCENDING'}
243+
]
244+
}
245+
],
246+
'fieldOverrides': [
247+
{
248+
'collectionGroup': 'posts',
249+
'fieldPath': 'myBigMapField',
250+
'indexes': []
251+
}
252+
]
253+
});
254+
255+
await firestore.setIndexConfigurationFromJSON(json);
256+
});
232257
},
233258
);
234259
}

packages/cloud_firestore/cloud_firestore/lib/src/firestore.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,20 @@ class FirebaseFirestore extends FirebasePluginPlatform {
323323
return _delegate.setIndexConfiguration(json);
324324
}
325325

326+
/// Configures indexing for local query execution. Any previous index configuration is overridden.
327+
///
328+
/// The index entries themselves are created asynchronously. You can continue to use queries that
329+
/// require indexing even if the indices are not yet available. Query execution will automatically
330+
/// start using the index once the index entries have been written.
331+
/// See Firebase documentation to learn how to configure your index configuration JSON file:
332+
/// https://firebase.google.com/docs/reference/firestore/indexes
333+
///
334+
/// This API is in preview mode and is subject to change.
335+
@experimental
336+
Future<void> setIndexConfigurationFromJSON(String json) async {
337+
return _delegate.setIndexConfiguration(json);
338+
}
339+
326340
@override
327341
// ignore: avoid_equals_and_hash_code_on_mutable_classes
328342
bool operator ==(Object other) =>

0 commit comments

Comments
 (0)