move to freezed and slice http batching

This commit is contained in:
shenlong-tanwen 2026-08-13 08:26:50 +05:30
parent de28149d7d
commit df060eec4f
2 changed files with 25 additions and 37 deletions

View file

@ -1,3 +1,7 @@
import 'package:freezed_annotation/freezed_annotation.dart';
part 'asset_metadata.model.freezed.dart';
enum RemoteAssetMetadataKey {
mobileApp("mobile-app");
@ -23,40 +27,24 @@ class RemoteAssetMetadataItem {
}
}
class RemoteAssetMobileAppMetadata extends RemoteAssetMetadataValue {
final String? cloudId;
final String? createdAt;
final String? adjustmentTime;
final String? latitude;
final String? longitude;
@freezed
abstract class RemoteAssetMobileAppMetadata extends RemoteAssetMetadataValue with _$RemoteAssetMobileAppMetadata {
const factory RemoteAssetMobileAppMetadata({
String? cloudId,
String? createdAt,
String? adjustmentTime,
String? latitude,
String? longitude,
}) = _RemoteAssetMobileAppMetadata;
const RemoteAssetMobileAppMetadata({
this.cloudId,
this.createdAt,
this.adjustmentTime,
this.latitude,
this.longitude,
});
const RemoteAssetMobileAppMetadata._();
@override
Map<String, dynamic> toJson() {
final map = <String, Object?>{};
if (cloudId != null) {
map["iCloudId"] = cloudId;
}
if (createdAt != null) {
map["createdAt"] = createdAt;
}
if (adjustmentTime != null) {
map["adjustmentTime"] = adjustmentTime;
}
if (latitude != null) {
map["latitude"] = latitude;
}
if (longitude != null) {
map["longitude"] = longitude;
}
return map;
}
Map<String, dynamic> toJson() => {
'iCloudId': ?cloudId,
'createdAt': ?createdAt,
'adjustmentTime': ?adjustmentTime,
'latitude': ?latitude,
'longitude': ?longitude,
};
}

View file

@ -1,6 +1,6 @@
import 'dart:async';
import 'dart:math' as math;
import 'package:collection/collection.dart';
import 'package:drift/drift.dart';
import 'package:flutter/foundation.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
@ -115,12 +115,12 @@ Future<void> _processCloudIdMappingsInBatches(
if (items.isNotEmpty) {
if (canBulkUpdate) {
for (int i = 0; i < items.length; i += _kUploadBatchSize) {
for (final batch in items.slices(_kUploadBatchSize)) {
if (cancellation.isCompleted) {
break;
}
final end = math.min(i + _kUploadBatchSize, items.length);
await _bulkUpdate(assetsApi, items.sublist(i, end), cancellation.future);
await _bulkUpdate(assetsApi, batch, cancellation.future);
}
} else {
await _sequentialUpdate(assetsApi, items, cancellation);