From e029852381fa1feb3e1f9bbd13624e2d0d13d3cb Mon Sep 17 00:00:00 2001 From: Krille Date: Thu, 20 Apr 2023 13:51:50 +0200 Subject: [PATCH] feat: Try out sembast database backend --- lib/utils/client_manager.dart | 14 ++++++- .../flutter_hive_collections_database.dart | 4 +- .../matrix_sdk_extensions/matrix_locals.dart | 2 +- pubspec.lock | 39 +++++++++++++++---- pubspec.yaml | 7 +++- 5 files changed, 54 insertions(+), 12 deletions(-) diff --git a/lib/utils/client_manager.dart b/lib/utils/client_manager.dart index 1ee71d49..1a4e93a3 100644 --- a/lib/utils/client_manager.dart +++ b/lib/utils/client_manager.dart @@ -3,6 +3,7 @@ import 'dart:convert'; import 'package:flutter/foundation.dart'; import 'package:hive_flutter/hive_flutter.dart'; +import 'package:idb_shim/idb_io.dart'; import 'package:matrix/encryption/utils/key_verification.dart'; import 'package:matrix/matrix.dart'; import 'package:path_provider/path_provider.dart'; @@ -109,7 +110,18 @@ abstract class ClientManager { EventTypes.RoomPowerLevels, }, logLevel: kReleaseMode ? Level.warning : Level.verbose, - databaseBuilder: FlutterHiveCollectionsDatabase.databaseBuilder, + databaseBuilder: (client) async { + final path = + await FlutterHiveCollectionsDatabase.findDatabasePath(client); + Logs().v('Store data at:', path); + final db = EasyIdbDatabase( + 'database_${client.clientName.replaceAll(' ', '_').toLowerCase()}', + factory: getIdbFactoryPersistent(path), + ); + await db.open(); + return db; + }, + legacyDatabaseBuilder: FlutterHiveCollectionsDatabase.databaseBuilder, supportedLoginTypes: { AuthenticationTypes.password, AuthenticationTypes.sso, diff --git a/lib/utils/matrix_sdk_extensions/flutter_hive_collections_database.dart b/lib/utils/matrix_sdk_extensions/flutter_hive_collections_database.dart index 932763c5..56a2d2da 100644 --- a/lib/utils/matrix_sdk_extensions/flutter_hive_collections_database.dart +++ b/lib/utils/matrix_sdk_extensions/flutter_hive_collections_database.dart @@ -63,7 +63,7 @@ class FlutterHiveCollectionsDatabase extends HiveCollectionsDatabase { final db = FlutterHiveCollectionsDatabase( 'hive_collections_${client.clientName.replaceAll(' ', '_').toLowerCase()}', - await _findDatabasePath(client), + await findDatabasePath(client), key: hiverCipher, ); try { @@ -79,7 +79,7 @@ class FlutterHiveCollectionsDatabase extends HiveCollectionsDatabase { return db; } - static Future _findDatabasePath(Client client) async { + static Future findDatabasePath(Client client) async { String path = client.clientName; if (!kIsWeb) { Directory directory; diff --git a/lib/utils/matrix_sdk_extensions/matrix_locals.dart b/lib/utils/matrix_sdk_extensions/matrix_locals.dart index 4fb461fa..d1caf1d7 100644 --- a/lib/utils/matrix_sdk_extensions/matrix_locals.dart +++ b/lib/utils/matrix_sdk_extensions/matrix_locals.dart @@ -309,6 +309,6 @@ class MatrixLocals extends MatrixLocalizations { String wasDirectChatDisplayName(String oldDisplayName) => l10n.wasDirectChatDisplayName(oldDisplayName); - //@override + @override String get unknownUser => l10n.user; } diff --git a/pubspec.lock b/pubspec.lock index 846a2581..ae9d7b54 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -345,6 +345,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.6.2" + easy_idb: + dependency: transitive + description: + name: easy_idb + sha256: "06c3e834f2d42cc20d78caf44441b3125767961d7687f58b56385ee8f7fcbd61" + url: "https://pub.dev" + source: hosted + version: "1.0.0" emoji_picker_flutter: dependency: "direct main" description: @@ -857,6 +865,14 @@ packages: url: "https://pub.dev" source: hosted version: "4.0.2" + idb_shim: + dependency: "direct main" + description: + name: idb_shim + sha256: "3ac9d6a90c29e2192d35c8386d7b20cb3865756f5b299d74a829d5b888776d26" + url: "https://pub.dev" + source: hosted + version: "2.3.0+2" image: dependency: transitive description: @@ -1066,19 +1082,20 @@ packages: matrix: dependency: "direct main" description: - name: matrix - sha256: "8c07fa7b558d28891ea2609542295e4bb3e8360545540b434abaf055dde3a59c" - url: "https://pub.dev" - source: hosted - version: "0.18.0" + path: "." + ref: "krille/easy_idb_database" + resolved-ref: "44c9a17961c46e6c1e8f9367fa210cea4953cadb" + url: "https://gitlab.com/famedly/company/frontend/famedlysdk.git" + source: git + version: "0.18.3" matrix_api_lite: dependency: transitive description: name: matrix_api_lite - sha256: "7c1af53ccdcaf69db1372f607cba48f4ac360595c9bc9e1420768adb2f1c3814" + sha256: "16d74a065a085adf30985e6068c9cc001e130979d1f186e40f733450a6583725" url: "https://pub.dev" source: hosted - version: "1.1.10" + version: "1.6.1" matrix_homeserver_recommendations: dependency: "direct main" description: @@ -1583,6 +1600,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.3.2" + sembast: + dependency: transitive + description: + name: sembast + sha256: "24829715d11c2c437e67b413f29ff91b5325daa9632f851d44deeea7a29bde9e" + url: "https://pub.dev" + source: hosted + version: "3.4.3+1" sentiment_dart: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 5e61bd22..3bece139 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -51,6 +51,7 @@ dependencies: hive: ^2.2.3 hive_flutter: ^1.1.0 http: ^0.13.4 + idb_shim: ^2.3.0+2 image_picker: ^0.8.4+8 intl: any just_audio: ^0.9.30 @@ -163,4 +164,8 @@ dependency_overrides: keyboard_shortcuts: git: url: https://github.com/TheOneWithTheBraid/keyboard_shortcuts.git - ref: null-safety \ No newline at end of file + ref: null-safety + matrix: + git: + url: https://gitlab.com/famedly/company/frontend/famedlysdk.git + ref: krille/easy_idb_database \ No newline at end of file