Skip to content

Commit f64adb1

Browse files
refactor hash service to use for loop instead
1 parent fa3a35f commit f64adb1

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

mobile/analysis_options.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ dart_code_metrics:
151151
- avoid-unnecessary-continue
152152
- avoid-unnecessary-nullable-return-type: false
153153
- binary-expression-operand-order
154-
- move-variable-outside-iteration
155154
- pattern-fields-ordering
156155
- prefer-abstract-final-static-class
157156
- prefer-commenting-future-delayed

mobile/lib/services/hash.service.dart

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,13 @@ class HashService {
4040
);
4141
hashesInDB.sort((a, b) => a.assetId.compareTo(b.assetId));
4242

43-
int assetIndex = 0;
4443
int dbIndex = 0;
45-
4644
int bytesProcessed = 0;
4745
final hashedAssets = <Asset>[];
4846
final toBeHashed = <_AssetPath>[];
4947
final toBeDeleted = <String>[];
5048

51-
while (assetIndex < assets.length) {
49+
for (int assetIndex = 0; assetIndex < assets.length; assetIndex++) {
5250
final asset = assets[assetIndex];
5351
DeviceAsset? matchingDbEntry;
5452

@@ -67,7 +65,6 @@ class HashService {
6765
hashedAssets.add(
6866
asset.copyWith(checksum: base64.encode(matchingDbEntry.hash)),
6967
);
70-
assetIndex++;
7168
continue;
7269
}
7370

@@ -77,19 +74,18 @@ class HashService {
7774
if (matchingDbEntry != null) {
7875
toBeDeleted.add(matchingDbEntry.assetId);
7976
}
80-
} else {
81-
bytesProcessed += await file.length();
82-
toBeHashed.add(_AssetPath(asset: asset, path: file.path));
83-
84-
if (_shouldProcessBatch(toBeHashed.length, bytesProcessed)) {
85-
hashedAssets.addAll(await _processBatch(toBeHashed, toBeDeleted));
86-
toBeHashed.clear();
87-
toBeDeleted.clear();
88-
bytesProcessed = 0;
89-
}
77+
continue;
9078
}
9179

92-
assetIndex++;
80+
bytesProcessed += await file.length();
81+
toBeHashed.add(_AssetPath(asset: asset, path: file.path));
82+
83+
if (_shouldProcessBatch(toBeHashed.length, bytesProcessed)) {
84+
hashedAssets.addAll(await _processBatch(toBeHashed, toBeDeleted));
85+
toBeHashed.clear();
86+
toBeDeleted.clear();
87+
bytesProcessed = 0;
88+
}
9389
}
9490
assert(dbIndex == hashesInDB.length, "All hashes should've been processed");
9591

0 commit comments

Comments
 (0)