mirror of
https://github.com/immich-app/immich.git
synced 2025-07-08 10:44:15 -04:00
pr changes
This commit is contained in:
parent
3739e86974
commit
7246bcfc5b
@ -94,6 +94,7 @@ custom_lint:
|
|||||||
- lib/repositories/*_api.repository.dart
|
- lib/repositories/*_api.repository.dart
|
||||||
- lib/domain/models/sync/sync_event.model.dart
|
- lib/domain/models/sync/sync_event.model.dart
|
||||||
- lib/{domain,infrastructure}/**/sync_stream.*
|
- lib/{domain,infrastructure}/**/sync_stream.*
|
||||||
|
- lib/{domain,infrastructure}/**/sync_api.*
|
||||||
- lib/infrastructure/repositories/*_api.repository.dart
|
- lib/infrastructure/repositories/*_api.repository.dart
|
||||||
- lib/infrastructure/utils/*.converter.dart
|
- lib/infrastructure/utils/*.converter.dart
|
||||||
# acceptable exceptions for the time being
|
# acceptable exceptions for the time being
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
import 'package:immich_mobile/domain/models/sync/sync_event.model.dart';
|
import 'package:immich_mobile/domain/models/sync/sync_event.model.dart';
|
||||||
|
import 'package:openapi/api.dart';
|
||||||
|
|
||||||
abstract interface class ISyncApiRepository {
|
abstract interface class ISyncApiRepository {
|
||||||
Future<void> ack(List<String> data);
|
Future<void> ack(List<String> data);
|
||||||
|
|
||||||
Stream<List<SyncEvent>> watchUserSyncEvent();
|
Stream<List<SyncEvent>> getSyncEvents(List<SyncRequestType> type);
|
||||||
|
|
||||||
Stream<List<SyncEvent>> watchPartnerSyncEvent();
|
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,8 @@ class SyncStreamService {
|
|||||||
|
|
||||||
Future<void> syncUsers() async {
|
Future<void> syncUsers() async {
|
||||||
_logger.info("Syncing User Changes");
|
_logger.info("Syncing User Changes");
|
||||||
_userSyncSubscription = _syncApiRepository.watchUserSyncEvent().listen(
|
_userSyncSubscription =
|
||||||
|
_syncApiRepository.getSyncEvents([SyncRequestType.usersV1]).listen(
|
||||||
_handleSyncEvents,
|
_handleSyncEvents,
|
||||||
onDone: () {
|
onDone: () {
|
||||||
_userSyncCompleter.complete();
|
_userSyncCompleter.complete();
|
||||||
@ -77,7 +78,7 @@ class SyncStreamService {
|
|||||||
Future<void> syncPartners() async {
|
Future<void> syncPartners() async {
|
||||||
_logger.info("Syncing Partner Changes");
|
_logger.info("Syncing Partner Changes");
|
||||||
_partnerSyncSubscription =
|
_partnerSyncSubscription =
|
||||||
_syncApiRepository.watchPartnerSyncEvent().listen(
|
_syncApiRepository.getSyncEvents([SyncRequestType.partnersV1]).listen(
|
||||||
_handleSyncEvents,
|
_handleSyncEvents,
|
||||||
onDone: () {
|
onDone: () {
|
||||||
_partnerSyncCompleter.complete();
|
_partnerSyncCompleter.complete();
|
||||||
|
@ -14,13 +14,8 @@ class SyncApiRepository implements ISyncApiRepository {
|
|||||||
SyncApiRepository(this._api);
|
SyncApiRepository(this._api);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Stream<List<SyncEvent>> watchUserSyncEvent() {
|
Stream<List<SyncEvent>> getSyncEvents(List<SyncRequestType> type) {
|
||||||
return _getSyncStream(SyncStreamDto(types: [SyncRequestType.usersV1]));
|
return _getSyncStream(SyncStreamDto(types: type));
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Stream<List<SyncEvent>> watchPartnerSyncEvent() {
|
|
||||||
return _getSyncStream(SyncStreamDto(types: [SyncRequestType.partnersV1]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -7,37 +7,21 @@ 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';
|
import 'package:logging/logging.dart';
|
||||||
|
|
||||||
class _SyncStreamDriver {
|
|
||||||
final _userSyncCache = AsyncCache.ephemeral();
|
|
||||||
final _partnerSyncCache = AsyncCache.ephemeral();
|
|
||||||
|
|
||||||
Future<void> syncUsers() => _userSyncCache.fetch(
|
|
||||||
() async => runInIsolate(
|
|
||||||
(ref) => ref.read(syncStreamServiceProvider).syncUsers(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
Future<void> syncPartners() => _partnerSyncCache.fetch(
|
|
||||||
() async => runInIsolate(
|
|
||||||
(ref) => ref.read(syncStreamServiceProvider).syncPartners(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class BackgroundSyncManager {
|
class BackgroundSyncManager {
|
||||||
final Logger _logger = Logger('BackgroundSyncManager');
|
final Logger _logger = Logger('BackgroundSyncManager');
|
||||||
Timer? _timer;
|
Timer? _timer;
|
||||||
final Duration _duration;
|
final Duration _duration;
|
||||||
// This allows us to keep synching in the background while allowing ondemand syncs
|
// This allows us to keep synching in the background while allowing ondemand syncs
|
||||||
final _driver = _SyncStreamDriver();
|
final _userSyncCache = AsyncCache.ephemeral();
|
||||||
|
final _partnerSyncCache = AsyncCache.ephemeral();
|
||||||
|
|
||||||
BackgroundSyncManager({required Duration duration}) : _duration = duration;
|
BackgroundSyncManager({required Duration duration}) : _duration = duration;
|
||||||
|
|
||||||
Timer _createTimer() {
|
Timer _createTimer() {
|
||||||
return Timer.periodic(_duration, (timer) async {
|
return Timer.periodic(_duration, (timer) async {
|
||||||
_logger.info('Background sync started');
|
_logger.info('Background sync started');
|
||||||
await _driver.syncUsers();
|
await syncUsers();
|
||||||
await _driver.syncPartners();
|
await syncPartners();
|
||||||
_logger.info('Background sync completed');
|
_logger.info('Background sync completed');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -53,6 +37,14 @@ class BackgroundSyncManager {
|
|||||||
_timer = null;
|
_timer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> syncUsers() => _driver.syncUsers();
|
Future<void> syncUsers() => _userSyncCache.fetch(
|
||||||
Future<void> syncPartners() => _driver.syncPartners();
|
() async => runInIsolate(
|
||||||
|
(ref) => ref.read(syncStreamServiceProvider).syncUsers(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
Future<void> syncPartners() => _partnerSyncCache.fetch(
|
||||||
|
() async => runInIsolate(
|
||||||
|
(ref) => ref.read(syncStreamServiceProvider).syncPartners(),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user