π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Load embeddings in a batch
vishnukvmd4d095208f6b4
diff --git a/lib/db/files_db.dart b/lib/db/files_db.dartindex 9b6afd50f0..c318bcf26d 100644--- a/lib/db/files_db.dart+++ b/lib/db/files_db.dart@@ -1594,6 +1594,31 @@ class FilesDB {return _convertToEmbeddings(results);}+ Future<List<Embedding>> getAllEmbeddingsV2() async {+ final db = await instance.database;+ final List<Embedding> allEmbeddings = [];++ int offset = 0;+ while (true) {+ final results = await db.query(+ embeddingsTable,+ orderBy: '$columnUploadedFileID ASC',+ limit: 5000,+ offset: offset,+ );++ if (results.isEmpty) {+ break; // No more results left to fetch+ }++ allEmbeddings.addAll(_convertToEmbeddings(results));++ offset += 5000; // Increment offset for the next batch+ }++ return allEmbeddings;+ }+Future<List<Embedding>> getUnSyncedEmbeddings() async {final db = await instance.database;final results = await db.query(diff --git a/lib/services/semantic_search/semantic_search_service.dart b/lib/services/semantic_search/semantic_search_service.dartindex 6ad314295d..dd01b5a61a 100644--- a/lib/services/semantic_search/semantic_search_service.dart+++ b/lib/services/semantic_search/semantic_search_service.dart@@ -161,7 +161,7 @@ class SemanticSearchService {}Future<IndexStatus> getIndexStatus() async {- final embeddings = await FilesDB.instance.getAllEmbeddings();+ final embeddings = await FilesDB.instance.getAllEmbeddingsV2();return IndexStatus(embeddings.length, _queue.length);}@@ -242,12 +242,12 @@ class SemanticSearchService {Future<void> _cacheEmbeddings() async {final startTime = DateTime.now();- final embeddings = await FilesDB.instance.getAllEmbeddings();+ final embeddings = await FilesDB.instance.getAllEmbeddingsV2();_cachedEmbeddings.clear();_cachedEmbeddings.addAll(embeddings);final endTime = DateTime.now();_logger.info(- "loadingAllEmbeddings took: ${(endTime.millisecondsSinceEpoch - startTime.millisecondsSinceEpoch)}ms",+ "Loading ${embeddings.length} embeddings took: ${(endTime.millisecondsSinceEpoch - startTime.millisecondsSinceEpoch)}ms",);}}diff --git a/pubspec.lock b/pubspec.lockindex 8611a8bc1f..95b36a0bca 100644--- a/pubspec.lock+++ b/pubspec.lock@@ -1865,18 +1865,18 @@ packages:dependency: "direct main"description:name: sqflite- sha256: b4d6710e1200e96845747e37338ea8a819a12b51689a3bcf31eff0003b37a0b9+ sha256: "591f1602816e9c31377d5f008c2d9ef7b8aca8941c3f89cc5fd9d84da0c38a9a"url: "https://pub.dev"source: hosted- version: "2.2.8+4"+ version: "2.3.0"sqflite_common:dependency: transitivedescription:name: sqflite_common- sha256: e77abf6ff961d69dfef41daccbb66b51e9983cdd5cb35bf30733598057401555+ sha256: "1b92f368f44b0dee2425bb861cfa17b6f6cf3961f762ff6f941d20b33355660a"url: "https://pub.dev"source: hosted- version: "2.4.5"+ version: "2.5.0"sqflite_migration:dependency: "direct main"description:diff --git a/pubspec.yaml b/pubspec.yamlindex 94f600280d..305e880f88 100644--- a/pubspec.yaml+++ b/pubspec.yaml@@ -130,7 +130,7 @@ dependencies:sentry_flutter: ^7.9.0share_plus: ^4.0.10shared_preferences: ^2.0.5- sqflite: ^2.0.0+3+ sqflite: ^2.3.0sqflite_migration: ^0.3.0step_progress_indicator: ^1.0.2styled_text: ^7.0.0