Move expensive ops to a separate isolate
This commit is contained in:
parent
7c06ea50b6
commit
811a4cb71e
2 changed files with 28 additions and 11 deletions
|
@ -114,16 +114,8 @@ class LocalSyncService {
|
|||
d.inMilliseconds.toString() +
|
||||
"ms");
|
||||
final existingIDs = await _db.getExistingLocalFileIDs();
|
||||
final List<LocalAsset> unsyncedAssets = [];
|
||||
for (final asset in localAssets) {
|
||||
if (!existingIDs.contains(asset.id)) {
|
||||
unsyncedAssets.add(asset);
|
||||
}
|
||||
}
|
||||
if (unsyncedAssets.isEmpty) {
|
||||
return false;
|
||||
}
|
||||
final unsyncedFiles = await convertToFiles(unsyncedAssets, _computer);
|
||||
final unsyncedFiles =
|
||||
await getUnsyncedFiles(localAssets, existingIDs, _computer);
|
||||
await _db.insertMultiple(unsyncedFiles);
|
||||
_logger.info(
|
||||
"Inserted " + unsyncedFiles.length.toString() + " unsynced files.");
|
||||
|
|
|
@ -45,7 +45,32 @@ Future<List<LocalAsset>> getAllLocalAssets() async {
|
|||
return assets;
|
||||
}
|
||||
|
||||
Future<List<File>> convertToFiles(
|
||||
Future<List<File>> getUnsyncedFiles(
|
||||
List<LocalAsset> assets, Set<String> existingIDs, Computer computer) async {
|
||||
final args = Map<String, dynamic>();
|
||||
args['assets'] = assets;
|
||||
args['existingIDs'] = existingIDs;
|
||||
final unsyncedAssets =
|
||||
await computer.compute(_getUnsyncedAssets, param: args);
|
||||
if (unsyncedAssets.isEmpty) {
|
||||
return [];
|
||||
}
|
||||
return _convertToFiles(unsyncedAssets, computer);
|
||||
}
|
||||
|
||||
List<LocalAsset> _getUnsyncedAssets(Map<String, dynamic> args) {
|
||||
final List<LocalAsset> assets = args['assets'];
|
||||
final Set<String> existingIDs = args['existingIDs'];
|
||||
final List<LocalAsset> unsyncedAssets = [];
|
||||
for (final asset in assets) {
|
||||
if (!existingIDs.contains(asset.id)) {
|
||||
unsyncedAssets.add(asset);
|
||||
}
|
||||
}
|
||||
return unsyncedAssets;
|
||||
}
|
||||
|
||||
Future<List<File>> _convertToFiles(
|
||||
List<LocalAsset> assets, Computer computer) async {
|
||||
final List<LocalAsset> recents = [];
|
||||
final List<LocalAssetEntity> entities = [];
|
||||
|
|
Loading…
Reference in a new issue