[mob] Fix impl diff compute & simplify
This commit is contained in:
@@ -4,6 +4,7 @@ import "package:path/path.dart";
|
||||
import "package:path_provider/path_provider.dart";
|
||||
import "package:photos/db/local/migration.dart";
|
||||
import "package:photos/log/devlog.dart";
|
||||
import "package:photos/services/remote_pull/local/import/model.dart";
|
||||
import "package:sqlite_async/sqlite_async.dart";
|
||||
|
||||
class LocalDB {
|
||||
@@ -23,6 +24,8 @@ class LocalDB {
|
||||
devLog("LocalDB init complete $path");
|
||||
}
|
||||
|
||||
Future<void> storeIncrementalDiff(IncrementalDiffWithOnDevice diff) async {}
|
||||
|
||||
Future<Set<String>> getAssetsIDs() async {
|
||||
final result = await _sqliteDB.execute("SELECT id FROM assets");
|
||||
final ids = <String>{};
|
||||
|
||||
0
mobile/lib/db/local/mappers.dart
Normal file
0
mobile/lib/db/local/mappers.dart
Normal file
@@ -20,7 +20,7 @@ class DeviceAssetsService {
|
||||
required int fromTimeInMs,
|
||||
required int toTimeInMs,
|
||||
}) async {
|
||||
final newOrUpdatedDevicePaths = await getDevicePathAssets(
|
||||
final newOrUpdatedDevicePaths = await _getDevicePathAssets(
|
||||
fromTimeInMs: fromTimeInMs,
|
||||
toTimeInMs: toTimeInMs,
|
||||
);
|
||||
@@ -46,7 +46,7 @@ class DeviceAssetsService {
|
||||
Map<String, Set<String>> inAppPathToLocalIDs,
|
||||
TimeLogger tL,
|
||||
) async {
|
||||
final allOnDeviceAssets = await getDevicePathAssets();
|
||||
final allOnDeviceAssets = await _getDevicePathAssets();
|
||||
final String logMsg = "fetched allDeviceAssets $tL";
|
||||
final r = await Computer.shared()
|
||||
.compute<FullDiffReqParams, FullDiffWithOnDevice>(
|
||||
@@ -62,7 +62,7 @@ class DeviceAssetsService {
|
||||
return r;
|
||||
}
|
||||
|
||||
Future<List<DevicePathAssets>> getDevicePathAssets({
|
||||
Future<List<DevicePathAssets>> _getDevicePathAssets({
|
||||
int? fromTimeInMs,
|
||||
int? toTimeInMs,
|
||||
}) async {
|
||||
@@ -226,19 +226,38 @@ class DeviceAssetsService {
|
||||
Future<IncrementalDiffWithOnDevice> _computeIncrementalDiffWithOnDevice(
|
||||
IncrementalDiffReqParams req,
|
||||
) async {
|
||||
final assetList = args["assetList"];
|
||||
final fromTimeInMs = args["fromTimeInMs"];
|
||||
final List<AssetEntity> filteredAssets = [];
|
||||
for (AssetEntity entity in assetList) {
|
||||
final bool assetCreatedOrUpdatedAfterGivenTime = max(
|
||||
entity.createDateTime.millisecondsSinceEpoch,
|
||||
entity.modifiedDateTime.millisecondsSinceEpoch,
|
||||
) >=
|
||||
(fromTimeInMs);
|
||||
if (assetCreatedOrUpdatedAfterGivenTime) {
|
||||
filteredAssets.add(entity);
|
||||
final List<AssetPathEntity> addedOrModifiedPaths = [];
|
||||
final List<AssetEntity> addedOrModifiedAssets = [];
|
||||
final Set<String> processedAssetIds = {};
|
||||
final Set<String> updatedInAppAssetIds = {};
|
||||
final Map<String, Set<String>> newOrUpdatedPathToLocalIDs = {};
|
||||
final int fromInSec = req.fromTimeInMs ~/ 1000;
|
||||
for (final DevicePathAssets pathAssets in req.newOrUpdatedLocalPaths) {
|
||||
final String pathID = pathAssets.path.id;
|
||||
final Set<String> localIDs = {};
|
||||
for (final AssetEntity asset in pathAssets.assets) {
|
||||
final String assetID = asset.id;
|
||||
localIDs.add(assetID);
|
||||
if (processedAssetIds.contains(assetID) ||
|
||||
max(asset.createDateSecond ?? 0, asset.modifiedDateSecond ?? 0) <
|
||||
fromInSec) {
|
||||
continue;
|
||||
}
|
||||
|
||||
processedAssetIds.add(assetID);
|
||||
addedOrModifiedAssets.add(asset);
|
||||
if (req.inAppAssetIDs.contains(assetID)) {
|
||||
updatedInAppAssetIds.add(assetID);
|
||||
}
|
||||
}
|
||||
|
||||
newOrUpdatedPathToLocalIDs[pathID] = localIDs;
|
||||
}
|
||||
return filteredAssets;
|
||||
return IncrementalDiffWithOnDevice(
|
||||
addedOrModifiedPaths,
|
||||
newOrUpdatedPathToLocalIDs,
|
||||
addedOrModifiedAssets,
|
||||
updatedInAppAssetIds,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,9 +73,9 @@ class LocalImportService {
|
||||
final syncTime = DateTime.now().microsecondsSinceEpoch;
|
||||
final Set<String> inAppAssetIds = await localDB.getAssetsIDs();
|
||||
_log.info("${inAppAssetIds.length} assets in app $tl");
|
||||
final IncrementalDiffWithOnDevice diff =
|
||||
await _deviceAssetsService.incrementalDiffWithOnDevice(
|
||||
final diff = await _deviceAssetsService.incrementalDiffWithOnDevice(
|
||||
inAppAssetIds,
|
||||
tl,
|
||||
fromTimeInMs: _prefs.getInt(lastLocalDBSyncTime) ?? 0,
|
||||
toTimeInMs: syncTime,
|
||||
);
|
||||
@@ -90,7 +90,6 @@ class LocalImportService {
|
||||
_log.info("incrementalSync completed $tl");
|
||||
}
|
||||
});
|
||||
|
||||
_existingSync?.complete();
|
||||
_existingSync = null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user