Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob] FDStatus: Store objectID and nonce

Neeraj Gupta6edacd2f1de2
diff --git a/mobile/lib/db/ml/db_fields.dart b/mobile/lib/db/ml/db_fields.dart
index a9438dc2ac..06f30ae9fd 100644
--- a/mobile/lib/db/ml/db_fields.dart
+++ b/mobile/lib/db/ml/db_fields.dart
@@ -114,6 +114,8 @@ CREATE TABLE IF NOT EXISTS $fileDataTable (
user_id INTEGER NOT NULL,
type TEXT NOT NULL,
size INTEGER NOT NULL,
+ obj_id TEXT,
+ obj_nonce TEXT,
updated_at INTEGER NOT NULL,
PRIMARY KEY ($fileIDColumn, type)
);
diff --git a/mobile/lib/db/ml/filedata.dart b/mobile/lib/db/ml/filedata.dart
index e2c6ee5f58..6e6afc9ef4 100644
--- a/mobile/lib/db/ml/filedata.dart
+++ b/mobile/lib/db/ml/filedata.dart
@@ -3,23 +3,25 @@ import "package:photos/db/ml/db_fields.dart";
import "package:photos/services/filedata/model/file_data.dart";
extension FileDataTable on MLDataDB {
- Future<void> putIndexStatus(List<IndexInfo> embeddings) async {
- if (embeddings.isEmpty) return;
+ Future<void> putFDStatus(List<FDStatus> fdStatusList) async {
+ if (fdStatusList.isEmpty) return;
final db = await MLDataDB.instance.asyncDB;
final inputs = <List<Object?>>[];
- for (var embedding in embeddings) {
+ for (var status in fdStatusList) {
inputs.add(
[
- embedding.fileID,
- embedding.userID,
- embedding.type,
- embedding.size,
- embedding.updatedAt,
+ status.fileID,
+ status.userID,
+ status.type,
+ status.size,
+ status.objectID,
+ status.objectNonce,
+ status.updatedAt,
],
);
}
await db.executeBatch(
- 'INSERT OR REPLACE INTO $fileDataTable ($fileIDColumn, user_id, type, size, updated_at) values(?, ?, ?, ?, ?)',
+ 'INSERT OR REPLACE INTO $fileDataTable ($fileIDColumn, user_id, type, size, obj_id, obj_nonce, updated_at ) values(?, ?, ?, ?, ?, ?, ?)',
inputs,
);
}
diff --git a/mobile/lib/services/filedata/filedata_service.dart b/mobile/lib/services/filedata/filedata_service.dart
index 48f4f851ae..12c3d68e3a 100644
--- a/mobile/lib/services/filedata/filedata_service.dart
+++ b/mobile/lib/services/filedata/filedata_service.dart
@@ -111,28 +111,32 @@ class FileDataService {
);
}
- Future<void> syncDiff() async {
+ Future<void> syncFDStatus() async {
try {
- _logger.info("syncDiff");
- final lastTime = _prefs.getInt("fd.lastSyncTime") ?? 1;
- final res = await _dio.post(
- "/files/data/status-diff",
- data: {
- "lastUpdated": lastTime,
- },
- );
- final data = res.data as List;
- final List<IndexInfo> info = [];
- int maxUpdatedAt = lastTime;
- for (var entry in data) {
- info.add(IndexInfo.fromJson(entry));
- if (entry["updatedAt"] > maxUpdatedAt) {
- maxUpdatedAt = entry["updatedAt"];
+ bool hasMoreData = false;
+ do {
+ final lastTime = _prefs.getInt("fd.lastSyncTimex") ?? 0;
+ final res = await _dio.post(
+ "/files/data/status-diff",
+ data: {
+ "lastUpdatedAt": lastTime,
+ },
+ );
+ final r = res.data;
+ final data = (r["diff"] ?? []) as List;
+ final List<FDStatus> result = [];
+ int maxUpdatedAt = lastTime;
+ for (var entry in data) {
+ result.add(FDStatus.fromJson(entry));
+ if (entry["updatedAt"] > maxUpdatedAt) {
+ maxUpdatedAt = entry["updatedAt"];
+ }
}
- }
- await MLDataDB.instance.putIndexStatus(info);
- await _prefs.setInt("fd.lastSyncTime", maxUpdatedAt);
- _logger.info('found ${info.length} entries');
+ await MLDataDB.instance.putFDStatus(result);
+ await _prefs.setInt("fd.lastSyncTime", maxUpdatedAt);
+ _logger.info('found ${result.length} fd entries');
+ hasMoreData = result.isNotEmpty;
+ } while (hasMoreData);
} catch (e) {
_logger.severe("Failed to syncDiff", e);
rethrow;
diff --git a/mobile/lib/services/filedata/model/file_data.dart b/mobile/lib/services/filedata/model/file_data.dart
index 2db7a105c7..4e479bdc7d 100644
--- a/mobile/lib/services/filedata/model/file_data.dart
+++ b/mobile/lib/services/filedata/model/file_data.dart
@@ -155,29 +155,36 @@ class RemoteClipEmbedding {
}
}
-class IndexInfo {
+// FDStatus represents the status of a file data entry.
+class FDStatus {
final int fileID;
final int userID;
final String type;
final bool isDeleted;
final int size;
final int updatedAt;
- IndexInfo({
+ final String? objectID;
+ final String? objectNonce;
+ FDStatus({
required this.fileID,
required this.userID,
required this.type,
required this.size,
required this.updatedAt,
this.isDeleted = false,
+ this.objectID,
+ this.objectNonce,
});
- factory IndexInfo.fromJson(Map<String, dynamic> json) {
- return IndexInfo(
+ factory FDStatus.fromJson(Map<String, dynamic> json) {
+ return FDStatus(
fileID: json['fileID'] as int,
userID: json['userID'] as int,
type: json['type'] as String,
isDeleted: json['isDeleted'] as bool? ?? false,
size: json['size'] as int,
+ objectID: json['objectID'] as String?,
+ objectNonce: json['objectNonce'] as String?,
updatedAt: json['updatedAt'] as int,
);
}
diff --git a/mobile/lib/services/machine_learning/ml_service.dart b/mobile/lib/services/machine_learning/ml_service.dart
index f942d5fd83..ef064068fd 100644
--- a/mobile/lib/services/machine_learning/ml_service.dart
+++ b/mobile/lib/services/machine_learning/ml_service.dart
@@ -115,6 +115,7 @@ class MLService {
}
Future<void> sync() async {
+ await FileDataService.instance.syncFDStatus();
await faceRecognitionService.sync();
}
@@ -125,8 +126,6 @@ class MLService {
}
if (_cannotRunMLFunction() && !force) return;
_isRunningML = true;
- FileDataService.instance.syncDiff().ignore();
-
await sync();
final int unclusteredFacesCount =