mirror of
https://github.com/immich-app/immich.git
synced 2025-07-09 03:04:16 -04:00
add processing logs
This commit is contained in:
parent
84d665ebad
commit
70263c5351
@ -5,9 +5,6 @@ const double downloadFailed = -2;
|
|||||||
// Number of log entries to retain on app start
|
// Number of log entries to retain on app start
|
||||||
const int kLogTruncateLimit = 250;
|
const int kLogTruncateLimit = 250;
|
||||||
|
|
||||||
// Duration for background sync
|
|
||||||
const Duration kBackgroundSyncDuration = Duration(minutes: 1);
|
|
||||||
|
|
||||||
// Hash batch limits
|
// Hash batch limits
|
||||||
const int kBatchHashFileLimit = 128;
|
const int kBatchHashFileLimit = 128;
|
||||||
const int kBatchHashSizeLimit = 1024 * 1024 * 1024; // 1GB
|
const int kBatchHashSizeLimit = 1024 * 1024 * 1024; // 1GB
|
||||||
|
@ -63,17 +63,25 @@ class SyncStreamService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
await _syncApiRepository.ack(acks.values.toList());
|
await _syncApiRepository.ack(acks.values.toList());
|
||||||
|
_logger.info("$types events processed");
|
||||||
} catch (error, stack) {
|
} catch (error, stack) {
|
||||||
_logger.warning("Error handling sync events", error, stack);
|
_logger.warning("Error handling sync events", error, stack);
|
||||||
}
|
}
|
||||||
streamCompleter.completeOnce();
|
streamCompleter.completeOnce();
|
||||||
},
|
},
|
||||||
onError: (_) => streamCompleter.completeOnce(),
|
onError: (error) {
|
||||||
|
_logger.warning("Error in sync stream for $types", error);
|
||||||
|
streamCompleter.completeOnce();
|
||||||
|
},
|
||||||
// onDone is required to be called in cases where the stream is empty
|
// onDone is required to be called in cases where the stream is empty
|
||||||
onDone: () => shouldSkipOnDone ? null : streamCompleter.completeOnce,
|
onDone: () {
|
||||||
|
_logger.info("$types stream done");
|
||||||
|
if (!shouldSkipOnDone) {
|
||||||
|
streamCompleter.completeOnce();
|
||||||
|
}
|
||||||
|
},
|
||||||
);
|
);
|
||||||
streamCompleter.future.whenComplete(subscription.cancel);
|
return await streamCompleter.future.whenComplete(subscription.cancel);
|
||||||
return await streamCompleter.future;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> syncUsers() => _syncEvent([SyncRequestType.usersV1]);
|
Future<void> syncUsers() => _syncEvent([SyncRequestType.usersV1]);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:immich_mobile/constants/constants.dart';
|
|
||||||
import 'package:immich_mobile/utils/background_sync.dart';
|
import 'package:immich_mobile/utils/background_sync.dart';
|
||||||
|
|
||||||
final backgroundSyncProvider = Provider<BackgroundSyncManager>(
|
final backgroundSyncProvider = Provider<BackgroundSyncManager>(
|
||||||
(ref) => BackgroundSyncManager(duration: kBackgroundSyncDuration),
|
(ref) => BackgroundSyncManager(),
|
||||||
);
|
);
|
||||||
|
@ -5,43 +5,20 @@ import 'dart:async';
|
|||||||
import 'package:async/async.dart';
|
import 'package:async/async.dart';
|
||||||
import 'package:immich_mobile/providers/infrastructure/sync_stream.provider.dart';
|
import 'package:immich_mobile/providers/infrastructure/sync_stream.provider.dart';
|
||||||
import 'package:immich_mobile/utils/isolate.dart';
|
import 'package:immich_mobile/utils/isolate.dart';
|
||||||
import 'package:logging/logging.dart';
|
|
||||||
|
|
||||||
class BackgroundSyncManager {
|
class BackgroundSyncManager {
|
||||||
final Logger _logger = Logger('BackgroundSyncManager');
|
// This prevents multiple syncs from running at the same time
|
||||||
Timer? _timer;
|
|
||||||
final Duration _duration;
|
|
||||||
// This allows us to keep synching in the background while allowing ondemand syncs
|
|
||||||
final _userSyncCache = AsyncCache.ephemeral();
|
final _userSyncCache = AsyncCache.ephemeral();
|
||||||
final _partnerSyncCache = AsyncCache.ephemeral();
|
final _partnerSyncCache = AsyncCache.ephemeral();
|
||||||
|
|
||||||
BackgroundSyncManager({required Duration duration}) : _duration = duration;
|
BackgroundSyncManager();
|
||||||
|
|
||||||
Timer _createTimer() {
|
|
||||||
return Timer.periodic(_duration, (timer) async {
|
|
||||||
_logger.info('Background sync started');
|
|
||||||
await syncUsers();
|
|
||||||
await syncPartners();
|
|
||||||
_logger.info('Background sync completed');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void start() {
|
|
||||||
_logger.info('Starting Background sync');
|
|
||||||
_timer ??= _createTimer();
|
|
||||||
}
|
|
||||||
|
|
||||||
void stop() {
|
|
||||||
_logger.info('Stopping Background sync');
|
|
||||||
_timer?.cancel();
|
|
||||||
_timer = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> syncUsers() => _userSyncCache.fetch(
|
Future<void> syncUsers() => _userSyncCache.fetch(
|
||||||
() async => runInIsolate(
|
() => runInIsolate(
|
||||||
(ref) => ref.read(syncStreamServiceProvider).syncUsers(),
|
(ref) => ref.read(syncStreamServiceProvider).syncUsers(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
Future<void> syncPartners() => _partnerSyncCache.fetch(
|
Future<void> syncPartners() => _partnerSyncCache.fetch(
|
||||||
() async => runInIsolate(
|
() async => runInIsolate(
|
||||||
(ref) => ref.read(syncStreamServiceProvider).syncPartners(),
|
(ref) => ref.read(syncStreamServiceProvider).syncPartners(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user