Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mob][photos] Only index locally if enough RAM

laurenspriem054a9deb59e2
diff --git a/mobile/lib/services/machine_learning/ml_service.dart b/mobile/lib/services/machine_learning/ml_service.dart
index d33e94f745..1c2542206f 100644
--- a/mobile/lib/services/machine_learning/ml_service.dart
+++ b/mobile/lib/services/machine_learning/ml_service.dart
@@ -28,6 +28,7 @@ import "package:photos/services/machine_learning/semantic_search/semantic_search
import "package:photos/services/user_remote_flag_service.dart";
import "package:photos/utils/ml_util.dart";
import "package:photos/utils/network_util.dart";
+import "package:photos/utils/ram_check_util.dart";
import "package:synchronized/synchronized.dart";
class MLService {
@@ -69,6 +70,9 @@ class MLService {
.getCachedBoolValue(UserRemoteFlagService.mlEnabled)) return;
_logger.info("init called");
+ // Check if the device has enough RAM to run local indexing
+ await checkDeviceTotalRAM();
+
// Get client name
final packageInfo = ServiceLocator.instance.packageInfo;
client = "${packageInfo.packageName}/${packageInfo.version}";
diff --git a/mobile/lib/utils/local_settings.dart b/mobile/lib/utils/local_settings.dart
index 0376b83c35..d576b2fbe4 100644
--- a/mobile/lib/utils/local_settings.dart
+++ b/mobile/lib/utils/local_settings.dart
@@ -1,4 +1,5 @@
import 'package:photos/core/constants.dart';
+import "package:photos/utils/ram_check_util.dart";
import 'package:shared_preferences/shared_preferences.dart';
enum AlbumSortKey {
@@ -57,7 +58,7 @@ class LocalSettings {
return getRateUsShownCount() < kRateUsPromptThreshold;
}
- bool get isMLIndexingEnabled => _prefs.getBool(_kisMLIndexingEnabled) ?? true;
+ bool get isMLIndexingEnabled => _prefs.getBool(_kisMLIndexingEnabled) ?? enoughRamForLocalIndexing;
bool get userEnabledMultiplePart =>
_prefs.getBool(kEnableMultiplePart) ?? false;
diff --git a/mobile/lib/utils/ram_check_util.dart b/mobile/lib/utils/ram_check_util.dart
new file mode 100644
index 0000000000..cf26fcd9d9
--- /dev/null
+++ b/mobile/lib/utils/ram_check_util.dart
@@ -0,0 +1,12 @@
+import "package:system_info_plus/system_info_plus.dart";
+
+/// The total amount of RAM in the device in MB
+int? deviceTotalRAM;
+
+bool get enoughRamForLocalIndexing => deviceTotalRAM == null || deviceTotalRAM! >= 5 * 1024;
+
+/// Return the total amount of RAM in the device in MB
+Future<int?> checkDeviceTotalRAM() async {
+ deviceTotalRAM ??= await SystemInfoPlus.physicalMemory; // returns in MB
+ return deviceTotalRAM;
+}
diff --git a/mobile/pubspec.lock b/mobile/pubspec.lock
index ed39789ae6..87517811da 100644
--- a/mobile/pubspec.lock
+++ b/mobile/pubspec.lock
@@ -2475,6 +2475,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.3.0+3"
+ system_info_plus:
+ dependency: "direct main"
+ description:
+ name: system_info_plus
+ sha256: b915c811c6605b802f3988859bc2bb79c95f735762a75b5451741f7a2b949d1b
+ url: "https://pub.dev"
+ source: hosted
+ version: "0.0.5"
term_glyph:
dependency: transitive
description:
diff --git a/mobile/pubspec.yaml b/mobile/pubspec.yaml
index 2b561e1dcd..a5b0724bf7 100644
--- a/mobile/pubspec.yaml
+++ b/mobile/pubspec.yaml
@@ -168,6 +168,7 @@ dependencies:
syncfusion_flutter_core: ^25.2.5
syncfusion_flutter_sliders: ^25.2.5
synchronized: ^3.1.0
+ system_info_plus: ^0.0.5
tuple: ^2.0.0
ua_client_hints: ^1.4.0
uni_links: ^0.5.1