Perf: Remove redundant calls via computer (#1043)
This commit is contained in:
commit
0d6a5fc435
2 changed files with 28 additions and 27 deletions
|
@ -16,7 +16,6 @@ const assetFetchPageSize = 2000;
|
|||
Future<Tuple2<List<LocalPathAsset>, List<File>>> getLocalPathAssetsAndFiles(
|
||||
int fromTime,
|
||||
int toTime,
|
||||
Computer computer,
|
||||
) async {
|
||||
final pathEntities = await _getGalleryList(
|
||||
updateFromTime: fromTime,
|
||||
|
@ -31,7 +30,11 @@ Future<Tuple2<List<LocalPathAsset>, List<File>>> getLocalPathAssetsAndFiles(
|
|||
final List<File> uniqueFiles = [];
|
||||
for (AssetPathEntity pathEntity in pathEntities) {
|
||||
final List<AssetEntity> assetsInPath = await _getAllAssetLists(pathEntity);
|
||||
final Tuple2<Set<String>, List<File>> result = await computer.compute(
|
||||
late Tuple2<Set<String>, List<File>> result;
|
||||
if (assetsInPath.isEmpty) {
|
||||
result = const Tuple2({}, []);
|
||||
} else {
|
||||
result = await Computer.shared().compute(
|
||||
_getLocalIDsAndFilesFromAssets,
|
||||
param: <String, dynamic>{
|
||||
"pathEntity": pathEntity,
|
||||
|
@ -44,6 +47,7 @@ Future<Tuple2<List<LocalPathAsset>, List<File>>> getLocalPathAssetsAndFiles(
|
|||
);
|
||||
alreadySeenLocalIDs.addAll(result.item1);
|
||||
uniqueFiles.addAll(result.item2);
|
||||
}
|
||||
localPathAssets.add(
|
||||
LocalPathAsset(
|
||||
localIDs: result.item1,
|
||||
|
@ -120,14 +124,13 @@ Future<LocalDiffResult> getDiffWithLocal(
|
|||
Set<String> existingIDs, // localIDs of files already imported in app
|
||||
Map<String, Set<String>> pathToLocalIDs,
|
||||
Set<String> invalidIDs,
|
||||
Computer computer,
|
||||
) async {
|
||||
final Map<String, dynamic> args = <String, dynamic>{};
|
||||
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",
|
||||
|
|
|
@ -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<void>? _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<LocalPathAsset>, List<File>> result =
|
||||
await getLocalPathAssetsAndFiles(fromTime, toTime, _computer);
|
||||
await getLocalPathAssetsAndFiles(fromTime, toTime);
|
||||
|
||||
final List<File> 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(),
|
||||
shouldAutoBackup:
|
||||
Configuration.instance.hasSelectedAllFoldersForBackup(),
|
||||
);
|
||||
|
||||
final List<File> files = result.item2;
|
||||
if (files.isNotEmpty) {
|
||||
_logger.info(
|
||||
"Loaded ${files.length} photos from " +
|
||||
DateTime.fromMicrosecondsSinceEpoch(fromTime).toString() +
|
||||
|
|
Loading…
Add table
Reference in a new issue