chore: Disable sembast cooperator at start up

This commit is contained in:
Krille Fear 2021-11-16 13:20:58 +01:00
parent 94f3be589a
commit 0f26809ddc
2 changed files with 10 additions and 17 deletions

View File

@ -11,7 +11,6 @@ linter:
analyzer: analyzer:
errors: errors:
implementation_imports: ignore
todo: ignore todo: ignore
exclude: exclude:
- lib/generated_plugin_registrant.dart - lib/generated_plugin_registrant.dart

View File

@ -5,7 +5,7 @@ import 'package:flutter/foundation.dart';
import 'package:hive_flutter/hive_flutter.dart'; import 'package:hive_flutter/hive_flutter.dart';
import 'package:matrix/encryption/utils/key_verification.dart'; import 'package:matrix/encryption/utils/key_verification.dart';
import 'package:matrix/matrix.dart'; import 'package:matrix/matrix.dart';
import 'package:matrix/src/utils/run_benchmarked.dart'; import 'package:sembast/sembast.dart';
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
import 'package:fluffychat/utils/platform_infos.dart'; import 'package:fluffychat/utils/platform_infos.dart';
@ -24,10 +24,7 @@ abstract class ClientManager {
} }
final clientNames = <String>{}; final clientNames = <String>{};
try { try {
final rawClientNames = await runBenchmarked( final rawClientNames = await Store().getItem(clientNamespace);
'Get client names',
() => Store().getItem(clientNamespace),
);
if (rawClientNames != null) { if (rawClientNames != null) {
final clientNamesList = final clientNamesList =
(jsonDecode(rawClientNames) as List).cast<String>(); (jsonDecode(rawClientNames) as List).cast<String>();
@ -42,13 +39,14 @@ abstract class ClientManager {
await Store().setItem(clientNamespace, jsonEncode(clientNames.toList())); await Store().setItem(clientNamespace, jsonEncode(clientNames.toList()));
} }
final clients = clientNames.map(createClient).toList(); final clients = clientNames.map(createClient).toList();
await Future.wait(clients.map((client) => runBenchmarked( disableSembastCooperator();
'Init client ${client.clientName}', await Future.wait(clients.map((client) => client
() => client.init( .init(
waitForFirstSync: false, waitForFirstSync: false,
waitUntilLoadCompletedLoaded: false, waitUntilLoadCompletedLoaded: false,
)) )
.catchError((e, s) => Logs().e('Unable to initialize client', e, s)))); .catchError((e, s) => Logs().e('Unable to initialize client', e, s))));
enableSembastCooperator();
if (clients.length > 1 && clients.any((c) => !c.isLogged())) { if (clients.length > 1 && clients.any((c) => !c.isLogged())) {
final loggedOutClients = clients.where((c) => !c.isLogged()).toList(); final loggedOutClients = clients.where((c) => !c.isLogged()).toList();
for (final client in loggedOutClients) { for (final client in loggedOutClients) {
@ -57,11 +55,7 @@ abstract class ClientManager {
clientNames.remove(client.clientName); clientNames.remove(client.clientName);
clients.remove(client); clients.remove(client);
} }
await runBenchmarked( await Store().setItem(clientNamespace, jsonEncode(clientNames.toList()));
'Update clientNamespaces',
() =>
Store().setItem(clientNamespace, jsonEncode(clientNames.toList())),
);
} }
return clients; return clients;
} }