mirror of
https://github.com/immich-app/immich.git
synced 2026-05-22 07:32:32 -04:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8c7bd28864 |
@@ -128,17 +128,31 @@ class BackgroundWorkerBgService extends BackgroundWorkerFlutterApi {
|
|||||||
_logger.info('iOS background upload started with maxSeconds: ${maxSeconds}s');
|
_logger.info('iOS background upload started with maxSeconds: ${maxSeconds}s');
|
||||||
final sw = Stopwatch()..start();
|
final sw = Stopwatch()..start();
|
||||||
try {
|
try {
|
||||||
final timeout = isRefresh ? const Duration(seconds: 5) : Duration(minutes: _isBackupEnabled ? 3 : 6);
|
final hashTimeout = isRefresh
|
||||||
if (!await _syncAssets(hashTimeout: timeout)) {
|
? Duration(seconds: (maxSeconds ?? 20) - 1)
|
||||||
_logger.warning("Remote sync did not complete successfully, skipping backup");
|
: Duration(minutes: _isBackupEnabled ? 3 : 6);
|
||||||
|
final budget = maxSeconds != null ? Duration(seconds: maxSeconds - 1) : null;
|
||||||
|
|
||||||
|
final sync = _ref?.read(backgroundSyncProvider);
|
||||||
|
if (sync == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run sync local, sync remote, hash and backup concurrently so the bg
|
||||||
|
// refresh task (20s budget) can make progress on all four instead of
|
||||||
|
// racing them sequentially. Phases are independent at the data layer:
|
||||||
|
// hash and handle_backup read drift state and tolerate stale reads
|
||||||
|
// (server-side dedup catches the rare race).
|
||||||
|
final localFuture = sync.syncLocal();
|
||||||
|
final remoteFuture = sync.syncRemote();
|
||||||
|
final hashFuture = sync.hashAssets().timeout(hashTimeout, onTimeout: () {});
|
||||||
final backupFuture = _handleBackup();
|
final backupFuture = _handleBackup();
|
||||||
if (maxSeconds != null) {
|
|
||||||
await backupFuture.timeout(Duration(seconds: maxSeconds - 1), onTimeout: () {});
|
final all = Future.wait<dynamic>([localFuture, remoteFuture, hashFuture, backupFuture]);
|
||||||
|
if (budget != null) {
|
||||||
|
await all.timeout(budget, onTimeout: () => <dynamic>[]);
|
||||||
} else {
|
} else {
|
||||||
await backupFuture;
|
await all;
|
||||||
}
|
}
|
||||||
} catch (error, stack) {
|
} catch (error, stack) {
|
||||||
_logger.severe("Failed to complete iOS background upload", error, stack);
|
_logger.severe("Failed to complete iOS background upload", error, stack);
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ class DriftLocalAlbumRepository extends DriftDatabaseRepository {
|
|||||||
innerJoin(_db.localAssetEntity, _db.localAlbumAssetEntity.assetId.equalsExp(_db.localAssetEntity.id)),
|
innerJoin(_db.localAssetEntity, _db.localAlbumAssetEntity.assetId.equalsExp(_db.localAssetEntity.id)),
|
||||||
])
|
])
|
||||||
..where(_db.localAlbumAssetEntity.albumId.equals(albumId) & _db.localAssetEntity.checksum.isNull())
|
..where(_db.localAlbumAssetEntity.albumId.equals(albumId) & _db.localAssetEntity.checksum.isNull())
|
||||||
..orderBy([OrderingTerm.asc(_db.localAssetEntity.id)]);
|
..orderBy([OrderingTerm.desc(_db.localAssetEntity.createdAt)]);
|
||||||
|
|
||||||
return query.map((row) => row.readTable(_db.localAssetEntity).toDto()).get();
|
return query.map((row) => row.readTable(_db.localAssetEntity).toDto()).get();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user