diff --git a/lib/services/local/local_sync_util.dart b/lib/services/local/local_sync_util.dart index 18b15a613..9589d2ca4 100644 --- a/lib/services/local/local_sync_util.dart +++ b/lib/services/local/local_sync_util.dart @@ -16,7 +16,6 @@ const assetFetchPageSize = 2000; Future, List>> getLocalPathAssetsAndFiles( int fromTime, int toTime, - Computer computer, ) async { final pathEntities = await _getGalleryList( updateFromTime: fromTime, @@ -31,19 +30,24 @@ Future, List>> getLocalPathAssetsAndFiles( final List uniqueFiles = []; for (AssetPathEntity pathEntity in pathEntities) { final List assetsInPath = await _getAllAssetLists(pathEntity); - final Tuple2, List> result = await computer.compute( - _getLocalIDsAndFilesFromAssets, - param: { - "pathEntity": pathEntity, - "fromTime": fromTime, - "alreadySeenLocalIDs": alreadySeenLocalIDs, - "assetList": assetsInPath, - }, - taskName: - "getLocalPathAssetsAndFiles-${pathEntity.name}-count-${assetsInPath.length}", - ); - alreadySeenLocalIDs.addAll(result.item1); - uniqueFiles.addAll(result.item2); + late Tuple2, List> result; + if (assetsInPath.isEmpty) { + result = const Tuple2({}, []); + } else { + result = await Computer.shared().compute( + _getLocalIDsAndFilesFromAssets, + param: { + "pathEntity": pathEntity, + "fromTime": fromTime, + "alreadySeenLocalIDs": alreadySeenLocalIDs, + "assetList": assetsInPath, + }, + taskName: + "getLocalPathAssetsAndFiles-${pathEntity.name}-count-${assetsInPath.length}", + ); + alreadySeenLocalIDs.addAll(result.item1); + uniqueFiles.addAll(result.item2); + } localPathAssets.add( LocalPathAsset( localIDs: result.item1, @@ -120,14 +124,13 @@ Future getDiffWithLocal( Set existingIDs, // localIDs of files already imported in app Map> pathToLocalIDs, Set invalidIDs, - Computer computer, ) async { final Map args = {}; args['assets'] = assets; args['existingIDs'] = existingIDs; args['invalidIDs'] = invalidIDs; args['pathToLocalIDs'] = pathToLocalIDs; - final LocalDiffResult diffResult = await computer.compute( + final LocalDiffResult diffResult = await Computer.shared().compute( _getLocalAssetsDiff, param: args, taskName: "getLocalAssetsDiff", diff --git a/lib/services/local_sync_service.dart b/lib/services/local_sync_service.dart index cbfe7d0fb..300592ea8 100644 --- a/lib/services/local_sync_service.dart +++ b/lib/services/local_sync_service.dart @@ -1,7 +1,6 @@ import 'dart:async'; import 'dart:io'; -import 'package:computer/computer.dart'; import 'package:flutter/foundation.dart'; import 'package:logging/logging.dart'; import 'package:photo_manager/photo_manager.dart'; @@ -24,7 +23,6 @@ import 'package:tuple/tuple.dart'; class LocalSyncService { final _logger = Logger("LocalSyncService"); final _db = FilesDB.instance; - final Computer _computer = Computer.shared(); late SharedPreferences _prefs; Completer? _existingSync; @@ -194,7 +192,6 @@ class LocalSyncService { existingLocalFileIDs, pathToLocalIDs, invalidIDs, - _computer, ); bool hasAnyMappingChanged = false; if (localDiffResult.newPathToLocalIDs?.isNotEmpty ?? false) { @@ -299,17 +296,18 @@ class LocalSyncService { required int toTime, }) async { final Tuple2, List> result = - await getLocalPathAssetsAndFiles(fromTime, toTime, _computer); - - // Update the mapping for device path_id to local file id. Also, keep track - // of newly discovered device paths - await FilesDB.instance.insertLocalAssets( - result.item1, - shouldAutoBackup: Configuration.instance.hasSelectedAllFoldersForBackup(), - ); + await getLocalPathAssetsAndFiles(fromTime, toTime); final List files = result.item2; if (files.isNotEmpty) { + // Update the mapping for device path_id to local file id. Also, keep track + // of newly discovered device paths + await FilesDB.instance.insertLocalAssets( + result.item1, + shouldAutoBackup: + Configuration.instance.hasSelectedAllFoldersForBackup(), + ); + _logger.info( "Loaded ${files.length} photos from " + DateTime.fromMicrosecondsSinceEpoch(fromTime).toString() +