more refactors and logs page handling

This commit is contained in:
shenlong-tanwen
2024-10-23 02:30:46 +05:30
parent 8f47645cdb
commit a0afea04d8
90 changed files with 2386 additions and 584 deletions
@@ -51,9 +51,9 @@ class AssetSyncService with LogMixin {
);
final assetsFromServer = await syncApiRepo.getFullSyncForUser(
lastId: lastAssetId,
limit: chunkSize,
updatedUntil: updatedTill,
lastId: lastAssetId,
userId: user.id,
);
if (assetsFromServer == null) {
@@ -92,8 +92,8 @@ class AssetSyncService with LogMixin {
final (toAdd, toUpdate, toRemove) = await _diffAssets(
newAssets,
existingAssets,
compare: compare,
isRemoteSync: isRemoteSync,
compare: compare,
);
final assetsToAdd = toAdd.followedBy(toUpdate);
@@ -111,7 +111,7 @@ class AssetSyncService with LogMixin {
}) async {
// fast paths for trivial cases: reduces memory usage during initial sync etc.
if (newAssets.isEmpty && inDb.isEmpty) {
return const (<Asset>[], <Asset>[], <Asset>[]);
return (<Asset>[], <Asset>[], <Asset>[]);
} else if (newAssets.isEmpty && isRemoteSync == null) {
// remove all from database
return (const <Asset>[], const <Asset>[], inDb);
+12 -12
View File
@@ -88,7 +88,8 @@ class HashService with LogMixin {
}
assert(hashesInDB.isEmpty, "All hashes should be processed at this point");
_assetHashRepository.deleteIds(orphanedHashes.map((e) => e.id!).toList());
await _assetHashRepository
.deleteIds(orphanedHashes.map((e) => e.id!).toList());
return hashedAssets;
}
@@ -103,21 +104,21 @@ class HashService with LogMixin {
final hashedAssets = <Asset>[];
for (final (index, hash) in hashes.indexed) {
// ignore: avoid-unsafe-collection-methods
final asset = toBeHashed.elementAt(index).asset;
if (hash?.length == 20) {
final asset = toBeHashed.elementAtOrNull(index)?.asset;
if (asset != null && hash?.length == 20) {
hashedAssets.add(asset.copyWith(hash: base64.encode(hash!)));
} else {
log.w("Failed to hash file ${asset.localId ?? '<null>'}, skipping");
log.w("Failed to hash file ${asset?.localId ?? '<null>'}, skipping");
}
}
// Store the cache for future retrieval
_assetHashRepository.upsertAll(hashedAssets.map((a) => DeviceAssetToHash(
localId: a.localId!,
hash: a.hash,
modifiedTime: a.modifiedTime,
)));
await _assetHashRepository
.upsertAll(hashedAssets.map((a) => DeviceAssetToHash(
localId: a.localId!,
hash: a.hash,
modifiedTime: a.modifiedTime,
)));
log.v("Hashed ${hashedAssets.length}/${toBeHashed.length} assets");
return hashedAssets;
@@ -127,8 +128,7 @@ class HashService with LogMixin {
/// Files that could not be hashed will have a `null` value
Future<List<Uint8List?>> _hashFiles(List<String> paths) async {
try {
final hashes = await _hostService.digestFiles(paths);
return hashes;
return await _hostService.digestFiles(paths);
} catch (e, s) {
log.e("Error occured while hashing assets", e, s);
}