Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
Move from ObjectBox to Isar (#1635)
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnukvmd authored Jan 6, 2024
2 parents b89e001 + 338f4e9 commit cb95b6b
Show file tree
Hide file tree
Showing 21 changed files with 1,079 additions and 423 deletions.
18 changes: 7 additions & 11 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ PODS:
- FlutterMacOS
- integration_test (0.0.1):
- Flutter
- isar_flutter_libs (1.0.0):
- Flutter
- libwebp (1.3.2):
- libwebp/demux (= 1.3.2)
- libwebp/mux (= 1.3.2)
Expand Down Expand Up @@ -133,10 +135,6 @@ PODS:
- nanopb/encode (= 2.30909.1)
- nanopb/decode (2.30909.1)
- nanopb/encode (2.30909.1)
- ObjectBox (1.9.0)
- objectbox_flutter_libs (0.0.1):
- Flutter
- ObjectBox (= 1.9.0)
- onnxruntime (0.0.1):
- Flutter
- onnxruntime-objc (= 1.15.1)
Expand Down Expand Up @@ -218,14 +216,14 @@ DEPENDENCIES:
- image_editor_common (from `.symlinks/plugins/image_editor_common/ios`)
- in_app_purchase_storekit (from `.symlinks/plugins/in_app_purchase_storekit/darwin`)
- integration_test (from `.symlinks/plugins/integration_test/ios`)
- isar_flutter_libs (from `.symlinks/plugins/isar_flutter_libs/ios`)
- local_auth_ios (from `.symlinks/plugins/local_auth_ios/ios`)
- media_extension (from `.symlinks/plugins/media_extension/ios`)
- media_kit_libs_ios_video (from `.symlinks/plugins/media_kit_libs_ios_video/ios`)
- media_kit_native_event_loop (from `.symlinks/plugins/media_kit_native_event_loop/ios`)
- media_kit_video (from `.symlinks/plugins/media_kit_video/ios`)
- motionphoto (from `.symlinks/plugins/motionphoto/ios`)
- move_to_background (from `.symlinks/plugins/move_to_background/ios`)
- objectbox_flutter_libs (from `.symlinks/plugins/objectbox_flutter_libs/ios`)
- onnxruntime (from `.symlinks/plugins/onnxruntime/ios`)
- open_mail_app (from `.symlinks/plugins/open_mail_app/ios`)
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
Expand Down Expand Up @@ -257,7 +255,6 @@ SPEC REPOS:
- libwebp
- Mantle
- nanopb
- ObjectBox
- onnxruntime-c
- onnxruntime-objc
- OrderedSet
Expand Down Expand Up @@ -308,6 +305,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/in_app_purchase_storekit/darwin"
integration_test:
:path: ".symlinks/plugins/integration_test/ios"
isar_flutter_libs:
:path: ".symlinks/plugins/isar_flutter_libs/ios"
local_auth_ios:
:path: ".symlinks/plugins/local_auth_ios/ios"
media_extension:
Expand All @@ -322,8 +321,6 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/motionphoto/ios"
move_to_background:
:path: ".symlinks/plugins/move_to_background/ios"
objectbox_flutter_libs:
:path: ".symlinks/plugins/objectbox_flutter_libs/ios"
onnxruntime:
:path: ".symlinks/plugins/onnxruntime/ios"
open_mail_app:
Expand Down Expand Up @@ -387,6 +384,7 @@ SPEC CHECKSUMS:
image_editor_common: d6f6644ae4a6de80481e89fe6d0a8c49e30b4b43
in_app_purchase_storekit: 4fb7ee9e824b1f09107fbfbbce8c4b276366dc43
integration_test: 13825b8a9334a850581300559b8839134b124670
isar_flutter_libs: b69f437aeab9c521821c3f376198c4371fa21073
libwebp: 1786c9f4ff8a279e4dac1e8f385004d5fc253009
local_auth_ios: c6cf091ded637a88f24f86a8875d8b0f526e2605
Mantle: c5aa8794a29a022dfbbfc9799af95f477a69b62d
Expand All @@ -397,15 +395,13 @@ SPEC CHECKSUMS:
motionphoto: d4a432b8c8f22fb3ad966258597c0103c9c5ff16
move_to_background: 39a5b79b26d577b0372cbe8a8c55e7aa9fcd3a2d
nanopb: d4d75c12cd1316f4a64e3c6963f879ecd4b5e0d5
ObjectBox: e7ff611291a0663380e0736b46786bcd077294ff
objectbox_flutter_libs: 0948d6feb7de4f7edaebc7a898b9e85b7fc2bc89
onnxruntime: e9346181d75b8dea8733bdae512a22c298962e00
onnxruntime-c: ebdcfd8650bcbd10121c125262f99dea681b92a3
onnxruntime-objc: ae7acec7a3d03eaf072d340afed7a35635c1c2a6
open_mail_app: 794172f6a22cd16319d3ddaf45e945b2f74952b0
OrderedSet: aaeb196f7fef5a9edf55d89760da9176ad40b93c
package_info_plus: fd030dabf36271f146f1f3beacd48f564b0f17f7
path_provider_foundation: eaf5b3e458fc0e5fbb9940fb09980e853fe058b8
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
photo_manager: 4f6810b7dfc4feb03b461ac1a70dacf91fba7604
PromisesObjC: c50d2056b5253dadbd6c2bea79b0674bd5a52fa4
ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825
Expand Down
10 changes: 4 additions & 6 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
DA6BE5E826B3BC8600656280 /* (null) in Resources */ = {isa = PBXBuildFile; };
DA6BE5E826B3BC8600656280 /* BuildFile in Resources */ = {isa = PBXBuildFile; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -213,7 +213,7 @@
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */,
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */,
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */,
DA6BE5E826B3BC8600656280 /* (null) in Resources */,
DA6BE5E826B3BC8600656280 /* BuildFile in Resources */,
277218A0270F596900FFE3CC /* GoogleService-Info.plist in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -291,6 +291,7 @@
"${BUILT_PRODUCTS_DIR}/image_editor_common/image_editor_common.framework",
"${BUILT_PRODUCTS_DIR}/in_app_purchase_storekit/in_app_purchase_storekit.framework",
"${BUILT_PRODUCTS_DIR}/integration_test/integration_test.framework",
"${BUILT_PRODUCTS_DIR}/isar_flutter_libs/isar_flutter_libs.framework",
"${BUILT_PRODUCTS_DIR}/libwebp/libwebp.framework",
"${BUILT_PRODUCTS_DIR}/local_auth_ios/local_auth_ios.framework",
"${BUILT_PRODUCTS_DIR}/media_extension/media_extension.framework",
Expand All @@ -300,7 +301,6 @@
"${BUILT_PRODUCTS_DIR}/motionphoto/motionphoto.framework",
"${BUILT_PRODUCTS_DIR}/move_to_background/move_to_background.framework",
"${BUILT_PRODUCTS_DIR}/nanopb/nanopb.framework",
"${BUILT_PRODUCTS_DIR}/objectbox_flutter_libs/objectbox_flutter_libs.framework",
"${BUILT_PRODUCTS_DIR}/open_mail_app/open_mail_app.framework",
"${BUILT_PRODUCTS_DIR}/package_info_plus/package_info_plus.framework",
"${BUILT_PRODUCTS_DIR}/path_provider_foundation/path_provider_foundation.framework",
Expand All @@ -317,7 +317,6 @@
"${BUILT_PRODUCTS_DIR}/video_thumbnail/video_thumbnail.framework",
"${BUILT_PRODUCTS_DIR}/volume_controller/volume_controller.framework",
"${BUILT_PRODUCTS_DIR}/wakelock_plus/wakelock_plus.framework",
"${PODS_XCFRAMEWORKS_BUILD_DIR}/ObjectBox/ObjectBox.framework/ObjectBox",
"${PODS_XCFRAMEWORKS_BUILD_DIR}/media_kit_libs_ios_video/Ass.framework/Ass",
"${PODS_XCFRAMEWORKS_BUILD_DIR}/media_kit_libs_ios_video/Avcodec.framework/Avcodec",
"${PODS_XCFRAMEWORKS_BUILD_DIR}/media_kit_libs_ios_video/Avfilter.framework/Avfilter",
Expand Down Expand Up @@ -371,6 +370,7 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/image_editor_common.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/in_app_purchase_storekit.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/integration_test.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/isar_flutter_libs.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/libwebp.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/local_auth_ios.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/media_extension.framework",
Expand All @@ -380,7 +380,6 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/motionphoto.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/move_to_background.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/nanopb.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/objectbox_flutter_libs.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/open_mail_app.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/package_info_plus.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/path_provider_foundation.framework",
Expand All @@ -397,7 +396,6 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/video_thumbnail.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/volume_controller.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/wakelock_plus.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ObjectBox.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Ass.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Avcodec.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Avfilter.framework",
Expand Down
4 changes: 2 additions & 2 deletions lib/core/configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import 'package:photos/core/constants.dart';
import 'package:photos/core/error-reporting/super_logging.dart';
import 'package:photos/core/event_bus.dart';
import 'package:photos/db/collections_db.dart';
import "package:photos/db/embeddings_db.dart";
import 'package:photos/db/files_db.dart';
import 'package:photos/db/memories_db.dart';
import "package:photos/db/object_box.dart";
import 'package:photos/db/public_keys_db.dart';
import 'package:photos/db/trash_db.dart';
import 'package:photos/db/upload_locks_db.dart';
Expand Down Expand Up @@ -159,7 +159,7 @@ class Configuration {
_secretKey = null;
await FilesDB.instance.clearTable();
SemanticSearchService.instance.hasInitialized
? await ObjectBox.instance.clearTable()
? await EmbeddingsDB.instance.clearTable()
: null;
await CollectionsDB.instance.clearTable();
await MemoriesDB.instance.clearTable();
Expand Down
66 changes: 66 additions & 0 deletions lib/db/embeddings_db.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import "dart:io";

import "package:isar/isar.dart";
import 'package:path_provider/path_provider.dart';
import "package:photos/core/event_bus.dart";
import "package:photos/events/embedding_updated_event.dart";
import "package:photos/models/embedding.dart";

class EmbeddingsDB {
late final Isar _isar;

EmbeddingsDB._privateConstructor();

static final EmbeddingsDB instance = EmbeddingsDB._privateConstructor();

Future<void> init() async {
final dir = await getApplicationDocumentsDirectory();
_isar = await Isar.open(
[EmbeddingSchema],
directory: dir.path,
);
await _clearDeprecatedStore(dir);
}

Future<void> clearTable() async {
await _isar.clear();
}

Future<List<Embedding>> getAll(Model model) async {
return _isar.embeddings.filter().modelEqualTo(model).findAll();
}

Future<void> put(Embedding embedding) {
return _isar.writeTxn(() async {
await _isar.embeddings.put(embedding);
Bus.instance.fire(EmbeddingUpdatedEvent());
});
}

Future<void> putMany(List<Embedding> embeddings) {
return _isar.writeTxn(() async {
await _isar.embeddings.putAll(embeddings);
Bus.instance.fire(EmbeddingUpdatedEvent());
});
}

Future<List<Embedding>> getUnsyncedEmbeddings() async {
return await _isar.embeddings.filter().updationTimeEqualTo(null).findAll();
}

Future<void> deleteAllForModel(Model model) async {
await _isar.writeTxn(() async {
final embeddings =
await _isar.embeddings.filter().modelEqualTo(model).findAll();
await _isar.embeddings.deleteAll(embeddings.map((e) => e.id).toList());
Bus.instance.fire(EmbeddingUpdatedEvent());
});
}

Future<void> _clearDeprecatedStore(Directory dir) async {
final deprecatedStore = Directory(dir.path + "/object-box-store");
if (await deprecatedStore.exists()) {
await deprecatedStore.delete(recursive: true);
}
}
}
27 changes: 0 additions & 27 deletions lib/db/object_box.dart

This file was deleted.

4 changes: 3 additions & 1 deletion lib/generated/intl/messages_en.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions lib/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,8 @@
"manageDeviceStorage": "Manage device storage",
"machineLearning": "Machine learning",
"magicSearch": "Magic search",
"magicSearchDescription": "Please use our Desktop app to index the pending items in your library.",
"magicSearchDescription": "Please note that this will result in a higher bandwidth and battery usage until all items are indexed.",
"loadingModel": "Downloading models...",
"status": "Status",
"indexedItems": "Indexed items",
"pendingItems": "Pending items",
Expand Down Expand Up @@ -704,7 +705,7 @@
"deleteAlbumsDialogBody": "This will delete all empty albums. This is useful when you want to reduce the clutter in your album list.",
"deleteProgress": "Deleting {currentlyDeleting} / {totalCount}",
"genericProgress": "Processing {currentlyProcessing} / {totalCount}",
"@genericProgress" : {
"@genericProgress": {
"description": "Generic progress text to display when processing multiple items",
"type": "text",
"placeholders": {
Expand All @@ -718,7 +719,6 @@
}
}
},

"permanentlyDelete": "Permanently delete",
"canOnlyCreateLinkForFilesOwnedByYou": "Can only create link for files owned by you",
"publicLinkCreated": "Public link created",
Expand Down Expand Up @@ -1187,4 +1187,4 @@
"changeLocationOfSelectedItems": "Change location of selected items?",
"editsToLocationWillOnlyBeSeenWithinEnte": "Edits to location will only be seen within Ente",
"cleanUncategorized": "Clean Uncategorized"
}
}
4 changes: 1 addition & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,7 @@ Future<void> _init(bool isBackground, {String via = ''}) async {
});
}
unawaited(FeatureFlagService.instance.init());
if (!isBackground) {
unawaited(SemanticSearchService.instance.init());
}
unawaited(SemanticSearchService.instance.init());
// Can not including existing tf/ml binaries as they are not being built
// from source.
// See https://gitlab.com/fdroid/fdroiddata/-/merge_requests/12671#note_1294346819
Expand Down
Loading

0 comments on commit cb95b6b

Please sign in to comment.