Skip to content

feat: setIndexConfigurationFromJSON() API. Allow users to pass JSON string #10029

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 2 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';
import 'dart:convert';

import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';
Expand Down Expand Up @@ -229,6 +230,30 @@ void runInstanceTests() {
fieldOverrides: [fieldOverride1, fieldOverride2],
);
});

test('setIndexConfigurationFromJSON()', () async {
final json = jsonEncode({
'indexes': [
{
'collectionGroup': 'posts',
'queryScope': 'COLLECTION',
'fields': [
{'fieldPath': 'author', 'arrayConfig': 'CONTAINS'},
{'fieldPath': 'timestamp', 'order': 'DESCENDING'}
]
}
],
'fieldOverrides': [
{
'collectionGroup': 'posts',
'fieldPath': 'myBigMapField',
'indexes': []
}
]
});

await firestore.setIndexConfigurationFromJSON(json);
});
},
);
}
14 changes: 14 additions & 0 deletions packages/cloud_firestore/cloud_firestore/lib/src/firestore.dart
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,20 @@ class FirebaseFirestore extends FirebasePluginPlatform {
return _delegate.setIndexConfiguration(json);
}

/// Configures indexing for local query execution. Any previous index configuration is overridden.
///
/// 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.
/// See Firebase documentation to learn how to configure your index configuration JSON file:
/// https://firebase.google.com/docs/reference/firestore/indexes
///
/// This API is in preview mode and is subject to change.
@experimental
Future<void> setIndexConfigurationFromJSON(String json) async {
return _delegate.setIndexConfiguration(json);
}

@override
// ignore: avoid_equals_and_hash_code_on_mutable_classes
bool operator ==(Object other) =>
Expand Down