mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
feat: handle SyncResetV1 (#20732)
* feat: handle SyncResetV1 * auto retry on reset and handle SyncCompleteV1 * fix tests --------- Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com> Co-authored-by: Alex <alex.tran1502@gmail.com>
This commit is contained in:
parent
5acf909235
commit
fd4c2acde8
6 changed files with 122 additions and 80 deletions
|
|
@ -18,7 +18,8 @@ class SyncApiRepository {
|
|||
}
|
||||
|
||||
Future<void> streamChanges(
|
||||
Function(List<SyncEvent>, Function() abort) onData, {
|
||||
Future<void> Function(List<SyncEvent>, Function() abort, Function() reset) onData, {
|
||||
Function()? onReset,
|
||||
int batchSize = kSyncEventBatchSize,
|
||||
http.Client? httpClient,
|
||||
}) async {
|
||||
|
|
@ -69,6 +70,8 @@ class SyncApiRepository {
|
|||
shouldAbort = true;
|
||||
}
|
||||
|
||||
final reset = onReset ?? () {};
|
||||
|
||||
try {
|
||||
final response = await client.send(request);
|
||||
|
||||
|
|
@ -91,12 +94,12 @@ class SyncApiRepository {
|
|||
continue;
|
||||
}
|
||||
|
||||
await onData(_parseLines(lines), abort);
|
||||
await onData(_parseLines(lines), abort, reset);
|
||||
lines.clear();
|
||||
}
|
||||
|
||||
if (lines.isNotEmpty && !shouldAbort) {
|
||||
await onData(_parseLines(lines), abort);
|
||||
await onData(_parseLines(lines), abort, reset);
|
||||
}
|
||||
} catch (error, stack) {
|
||||
_logger.severe("Error processing stream", error, stack);
|
||||
|
|
@ -156,7 +159,8 @@ const _kResponseMap = <SyncEntityType, Function(Object)>{
|
|||
SyncEntityType.albumToAssetV1: SyncAlbumToAssetV1.fromJson,
|
||||
SyncEntityType.albumToAssetBackfillV1: SyncAlbumToAssetV1.fromJson,
|
||||
SyncEntityType.albumToAssetDeleteV1: SyncAlbumToAssetDeleteV1.fromJson,
|
||||
SyncEntityType.syncAckV1: _SyncAckV1.fromJson,
|
||||
SyncEntityType.syncAckV1: _SyncEmptyDto.fromJson,
|
||||
SyncEntityType.syncResetV1: _SyncEmptyDto.fromJson,
|
||||
SyncEntityType.memoryV1: SyncMemoryV1.fromJson,
|
||||
SyncEntityType.memoryDeleteV1: SyncMemoryDeleteV1.fromJson,
|
||||
SyncEntityType.memoryToAssetV1: SyncMemoryAssetV1.fromJson,
|
||||
|
|
@ -172,8 +176,9 @@ const _kResponseMap = <SyncEntityType, Function(Object)>{
|
|||
SyncEntityType.personDeleteV1: SyncPersonDeleteV1.fromJson,
|
||||
SyncEntityType.assetFaceV1: SyncAssetFaceV1.fromJson,
|
||||
SyncEntityType.assetFaceDeleteV1: SyncAssetFaceDeleteV1.fromJson,
|
||||
SyncEntityType.syncCompleteV1: _SyncEmptyDto.fromJson,
|
||||
};
|
||||
|
||||
class _SyncAckV1 {
|
||||
static _SyncAckV1? fromJson(dynamic _) => _SyncAckV1();
|
||||
class _SyncEmptyDto {
|
||||
static _SyncEmptyDto? fromJson(dynamic _) => _SyncEmptyDto();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue