Skip to content

armgit / ente

Public Imported from GitHub
0

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

Add support for early validation of photo

Neeraj Guptad833ba31edfa
diff --git a/lib/db/file_updation_db.dart b/lib/db/file_updation_db.dart
index dd12b5f2ed..6496b71ed3 100644
--- a/lib/db/file_updation_db.dart
+++ b/lib/db/file_updation_db.dart
@@ -128,6 +128,18 @@ class FileUpdationDB {
);
}
+ // check if entry existing for given localID and reason
+ Future<bool> isExisting(String localID, String reason) async {
+ final db = await instance.database;
+ final String whereClause =
+ '$columnLocalID = "$localID" AND $columnReason = "$reason"';
+ final rows = await db.query(
+ tableName,
+ where: whereClause,
+ );
+ return rows.isNotEmpty;
+ }
+
Future<List<String>> getLocalIDsForPotentialReUpload(
int limit,
String reason,
diff --git a/lib/services/local_file_update_service.dart b/lib/services/local_file_update_service.dart
index 5d05193f79..5219376b75 100644
--- a/lib/services/local_file_update_service.dart
+++ b/lib/services/local_file_update_service.dart
@@ -9,6 +9,7 @@ import 'package:photos/db/file_updation_db.dart';
import 'package:photos/db/files_db.dart';
import "package:photos/extensions/list.dart";
import "package:photos/extensions/stop_watch.dart";
+import "package:photos/models/file/extensions/file_props.dart";
import 'package:photos/models/file/file.dart';
import 'package:photos/models/file/file_type.dart';
import "package:photos/services/files_service.dart";
@@ -209,6 +210,27 @@ class LocalFileUpdateService {
);
}
+ Future<void> checkLivePhoto(EnteFile file) async {
+ if (file.localID == null ||
+ file.localID!.isEmpty ||
+ !file.isUploaded ||
+ file.fileType != FileType.livePhoto ||
+ !file.isOwner) {
+ return;
+ }
+ if (_prefs.containsKey(_iosLivePhotoSizeMigrationDone)) {
+ return;
+ }
+ bool hasEntry = await _fileUpdationDB.isExisting(
+ file.localID!,
+ FileUpdationDB.livePhotoCheck,
+ );
+ if (hasEntry) {
+ _logger.info('eager checkLivePhoto ${file.tag}');
+ await _checkLivePhotoWithLowOrUnknownSize([file.localID!]);
+ }
+ }
+
Future<void> _handleLivePhotosSizedCheck() async {
try {
if (_prefs.containsKey(_iosLivePhotoSizeMigrationDone)) {
@@ -226,12 +248,15 @@ class LocalFileUpdateService {
FileUpdationDB.livePhotoCheck,
);
if (localIDsToProcess.isNotEmpty) {
- final chunks = localIDsToProcess.chunks(10);
- for (final chunk in chunks) {
+ final chunksOf50 = localIDsToProcess.chunks(50);
+ for (final chunk in chunksOf50) {
final sTime = DateTime.now().microsecondsSinceEpoch;
- await _checkLivePhotoWithLowOrUnknownSize(
- chunk,
- );
+ final List<Future> futures = [];
+ final chunkOf10 = chunk.chunks(10);
+ for (final smallChunk in chunkOf10) {
+ futures.add(_checkLivePhotoWithLowOrUnknownSize(smallChunk));
+ }
+ await Future.wait(futures);
final eTime = DateTime.now().microsecondsSinceEpoch;
final d = Duration(microseconds: eTime - sTime);
_logger.info(
diff --git a/lib/ui/viewer/file/zoomable_live_image_new.dart b/lib/ui/viewer/file/zoomable_live_image_new.dart
index 1ad54660a5..51ba8e41f3 100644
--- a/lib/ui/viewer/file/zoomable_live_image_new.dart
+++ b/lib/ui/viewer/file/zoomable_live_image_new.dart
@@ -10,6 +10,7 @@ import "package:photos/models/file/extensions/file_props.dart";
import 'package:photos/models/file/file.dart';
import "package:photos/models/metadata/file_magic.dart";
import "package:photos/services/file_magic_service.dart";
+import "package:photos/services/local_file_update_service.dart";
import 'package:photos/ui/viewer/file/zoomable_image.dart';
import 'package:photos/utils/file_util.dart';
import 'package:photos/utils/toast_util.dart';
@@ -46,6 +47,9 @@ class _ZoomableLiveImageNewState extends State<ZoomableLiveImageNew>
_logger.info(
'initState for ${_enteFile.generatedID} with tag ${_enteFile.tag} and name ${_enteFile.displayName}',
);
+ if (_enteFile.isLivePhoto && _enteFile.isUploaded) {
+ LocalFileUpdateService.instance.checkLivePhoto(_enteFile).ignore();
+ }
super.initState();
}