Переглянути джерело

Speed up local file update check by running parallel checks (#1571)

Neeraj Gupta 1 рік тому
батько
коміт
a9c90ccdfa

+ 12 - 0
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,

+ 30 - 5
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(

+ 4 - 0
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();
   }
 

+ 1 - 1
pubspec.yaml

@@ -12,7 +12,7 @@ description: ente photos application
 # Read more about iOS versioning at
 # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
 
-version: 0.8.12+532
+version: 0.8.13+533
 
 environment:
   sdk: ">=3.0.0 <4.0.0"