mirror of
https://github.com/samsonjs/immich.git
synced 2026-04-27 15:07:45 +00:00
fix: show only local assets from albums selected for backup (#20050)
* show only local assets from albums selected for backup # Conflicts: # mobile/lib/infrastructure/repositories/db.repository.drift.dart * ignore backup selection * fix: backup album ownerId * fix: backup album ownerId * only show local only assets that are selected for backup * add index on visibility and backup selection * fix: video not playing in search view * remove safe area from bottom bar * refactor stack count with a CTE and local asset with a SELECT * fix lint * remove redundant COALESCE * remove stack count from main timeline query --------- 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
92384c28de
commit
08122d6871
19 changed files with 152 additions and 186 deletions
BIN
mobile/drift_schemas/main/drift_schema_v4.json
generated
BIN
mobile/drift_schemas/main/drift_schema_v4.json
generated
Binary file not shown.
|
|
@ -15,7 +15,6 @@ class RemoteAsset extends BaseAsset {
|
||||||
final AssetVisibility visibility;
|
final AssetVisibility visibility;
|
||||||
final String ownerId;
|
final String ownerId;
|
||||||
final String? stackId;
|
final String? stackId;
|
||||||
final int stackCount;
|
|
||||||
|
|
||||||
const RemoteAsset({
|
const RemoteAsset({
|
||||||
required this.id,
|
required this.id,
|
||||||
|
|
@ -34,7 +33,6 @@ class RemoteAsset extends BaseAsset {
|
||||||
this.visibility = AssetVisibility.timeline,
|
this.visibility = AssetVisibility.timeline,
|
||||||
super.livePhotoVideoId,
|
super.livePhotoVideoId,
|
||||||
this.stackId,
|
this.stackId,
|
||||||
this.stackCount = 0,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -61,7 +59,6 @@ class RemoteAsset extends BaseAsset {
|
||||||
thumbHash: ${thumbHash ?? "<NA>"},
|
thumbHash: ${thumbHash ?? "<NA>"},
|
||||||
visibility: $visibility,
|
visibility: $visibility,
|
||||||
stackId: ${stackId ?? "<NA>"},
|
stackId: ${stackId ?? "<NA>"},
|
||||||
stackCount: $stackCount,
|
|
||||||
checksum: $checksum,
|
checksum: $checksum,
|
||||||
livePhotoVideoId: ${livePhotoVideoId ?? "<NA>"},
|
livePhotoVideoId: ${livePhotoVideoId ?? "<NA>"},
|
||||||
}''';
|
}''';
|
||||||
|
|
@ -77,8 +74,7 @@ class RemoteAsset extends BaseAsset {
|
||||||
ownerId == other.ownerId &&
|
ownerId == other.ownerId &&
|
||||||
thumbHash == other.thumbHash &&
|
thumbHash == other.thumbHash &&
|
||||||
visibility == other.visibility &&
|
visibility == other.visibility &&
|
||||||
stackId == other.stackId &&
|
stackId == other.stackId;
|
||||||
stackCount == other.stackCount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -89,8 +85,7 @@ class RemoteAsset extends BaseAsset {
|
||||||
localId.hashCode ^
|
localId.hashCode ^
|
||||||
thumbHash.hashCode ^
|
thumbHash.hashCode ^
|
||||||
visibility.hashCode ^
|
visibility.hashCode ^
|
||||||
stackId.hashCode ^
|
stackId.hashCode;
|
||||||
stackCount.hashCode;
|
|
||||||
|
|
||||||
RemoteAsset copyWith({
|
RemoteAsset copyWith({
|
||||||
String? id,
|
String? id,
|
||||||
|
|
@ -109,7 +104,6 @@ class RemoteAsset extends BaseAsset {
|
||||||
AssetVisibility? visibility,
|
AssetVisibility? visibility,
|
||||||
String? livePhotoVideoId,
|
String? livePhotoVideoId,
|
||||||
String? stackId,
|
String? stackId,
|
||||||
int? stackCount,
|
|
||||||
}) {
|
}) {
|
||||||
return RemoteAsset(
|
return RemoteAsset(
|
||||||
id: id ?? this.id,
|
id: id ?? this.id,
|
||||||
|
|
@ -128,7 +122,6 @@ class RemoteAsset extends BaseAsset {
|
||||||
visibility: visibility ?? this.visibility,
|
visibility: visibility ?? this.visibility,
|
||||||
livePhotoVideoId: livePhotoVideoId ?? this.livePhotoVideoId,
|
livePhotoVideoId: livePhotoVideoId ?? this.livePhotoVideoId,
|
||||||
stackId: stackId ?? this.stackId,
|
stackId: stackId ?? this.stackId,
|
||||||
stackCount: stackCount ?? this.stackCount,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,16 @@
|
||||||
import 'remote_asset.entity.dart';
|
import 'remote_asset.entity.dart';
|
||||||
import 'local_asset.entity.dart';
|
|
||||||
import 'stack.entity.dart';
|
import 'stack.entity.dart';
|
||||||
|
import 'local_asset.entity.dart';
|
||||||
|
import 'local_album.entity.dart';
|
||||||
|
import 'local_album_asset.entity.dart';
|
||||||
|
|
||||||
mergedAsset: SELECT * FROM
|
mergedAsset:
|
||||||
(
|
|
||||||
SELECT
|
SELECT
|
||||||
rae.id as remote_id,
|
rae.id as remote_id,
|
||||||
lae.id as local_id,
|
(SELECT lae.id FROM local_asset_entity lae WHERE lae.checksum = rae.checksum LIMIT 1) as local_id,
|
||||||
rae.name,
|
rae.name,
|
||||||
rae."type",
|
rae."type",
|
||||||
rae.created_at,
|
rae.created_at as created_at,
|
||||||
rae.updated_at,
|
rae.updated_at,
|
||||||
rae.width,
|
rae.width,
|
||||||
rae.height,
|
rae.height,
|
||||||
|
|
@ -20,39 +21,28 @@ mergedAsset: SELECT * FROM
|
||||||
rae.owner_id,
|
rae.owner_id,
|
||||||
rae.live_photo_video_id,
|
rae.live_photo_video_id,
|
||||||
0 as orientation,
|
0 as orientation,
|
||||||
rae.stack_id,
|
rae.stack_id
|
||||||
COALESCE(stack_count.total_count, 0) AS stack_count
|
|
||||||
FROM
|
FROM
|
||||||
remote_asset_entity rae
|
remote_asset_entity rae
|
||||||
LEFT JOIN
|
|
||||||
local_asset_entity lae ON rae.checksum = lae.checksum
|
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
stack_entity se ON rae.stack_id = se.id
|
stack_entity se ON rae.stack_id = se.id
|
||||||
LEFT JOIN
|
|
||||||
(SELECT
|
|
||||||
stack_id,
|
|
||||||
COUNT(*) AS total_count
|
|
||||||
FROM remote_asset_entity
|
|
||||||
WHERE deleted_at IS NULL
|
|
||||||
AND visibility = 0
|
|
||||||
AND stack_id IS NOT NULL
|
|
||||||
GROUP BY stack_id
|
|
||||||
) AS stack_count ON rae.stack_id = stack_count.stack_id
|
|
||||||
WHERE
|
WHERE
|
||||||
rae.deleted_at IS NULL
|
rae.deleted_at IS NULL
|
||||||
AND rae.visibility = 0
|
AND rae.visibility = 0 -- timeline visibility
|
||||||
AND rae.owner_id in ?
|
AND rae.owner_id in ?
|
||||||
AND (
|
AND (
|
||||||
rae.stack_id IS NULL
|
rae.stack_id IS NULL
|
||||||
OR rae.id = se.primary_asset_id
|
OR rae.id = se.primary_asset_id
|
||||||
)
|
)
|
||||||
|
|
||||||
UNION ALL
|
UNION ALL
|
||||||
|
|
||||||
SELECT
|
SELECT
|
||||||
NULL as remote_id,
|
NULL as remote_id,
|
||||||
lae.id as local_id,
|
lae.id as local_id,
|
||||||
lae.name,
|
lae.name,
|
||||||
lae."type",
|
lae."type",
|
||||||
lae.created_at,
|
lae.created_at as created_at,
|
||||||
lae.updated_at,
|
lae.updated_at,
|
||||||
lae.width,
|
lae.width,
|
||||||
lae.height,
|
lae.height,
|
||||||
|
|
@ -63,14 +53,16 @@ mergedAsset: SELECT * FROM
|
||||||
NULL as owner_id,
|
NULL as owner_id,
|
||||||
NULL as live_photo_video_id,
|
NULL as live_photo_video_id,
|
||||||
lae.orientation,
|
lae.orientation,
|
||||||
NULL as stack_id,
|
NULL as stack_id
|
||||||
0 AS stack_count
|
|
||||||
FROM
|
FROM
|
||||||
local_asset_entity lae
|
local_asset_entity lae
|
||||||
LEFT JOIN
|
WHERE NOT EXISTS (
|
||||||
remote_asset_entity rae ON rae.checksum = lae.checksum
|
SELECT 1 FROM remote_asset_entity rae WHERE rae.checksum = lae.checksum
|
||||||
WHERE
|
)
|
||||||
rae.id IS NULL
|
AND EXISTS (
|
||||||
|
SELECT 1 FROM local_album_asset_entity laa
|
||||||
|
INNER JOIN local_album_entity la on laa.album_id = la.id
|
||||||
|
WHERE laa.asset_id = lae.id AND la.backup_selection = 0 -- selected
|
||||||
)
|
)
|
||||||
ORDER BY created_at DESC
|
ORDER BY created_at DESC
|
||||||
LIMIT $limit;
|
LIMIT $limit;
|
||||||
|
|
@ -85,17 +77,14 @@ SELECT
|
||||||
FROM
|
FROM
|
||||||
(
|
(
|
||||||
SELECT
|
SELECT
|
||||||
rae.name,
|
|
||||||
rae.created_at
|
rae.created_at
|
||||||
FROM
|
FROM
|
||||||
remote_asset_entity rae
|
remote_asset_entity rae
|
||||||
LEFT JOIN
|
|
||||||
local_asset_entity lae ON rae.checksum = lae.checksum
|
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
stack_entity se ON rae.stack_id = se.id
|
stack_entity se ON rae.stack_id = se.id
|
||||||
WHERE
|
WHERE
|
||||||
rae.deleted_at IS NULL
|
rae.deleted_at IS NULL
|
||||||
AND rae.visibility = 0
|
AND rae.visibility = 0 -- timeline visibility
|
||||||
AND rae.owner_id in ?
|
AND rae.owner_id in ?
|
||||||
AND (
|
AND (
|
||||||
rae.stack_id IS NULL
|
rae.stack_id IS NULL
|
||||||
|
|
@ -103,14 +92,18 @@ FROM
|
||||||
)
|
)
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT
|
SELECT
|
||||||
lae.name,
|
|
||||||
lae.created_at
|
lae.created_at
|
||||||
FROM
|
FROM
|
||||||
local_asset_entity lae
|
local_asset_entity lae
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
remote_asset_entity rae ON rae.checksum = lae.checksum
|
remote_asset_entity rae ON rae.checksum = lae.checksum
|
||||||
|
LEFT JOIN
|
||||||
|
local_album_asset_entity laa ON laa.asset_id = lae.id
|
||||||
|
LEFT JOIN
|
||||||
|
local_album_entity la ON la.id = laa.album_id
|
||||||
WHERE
|
WHERE
|
||||||
rae.id IS NULL
|
rae.id IS NULL
|
||||||
|
AND la.backup_selection = 0 -- selected
|
||||||
)
|
)
|
||||||
GROUP BY bucket_date
|
GROUP BY bucket_date
|
||||||
ORDER BY bucket_date DESC;
|
ORDER BY bucket_date DESC;
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -50,7 +50,7 @@ class DriftBackupRepository extends DriftDatabaseRepository {
|
||||||
return query.get().then((rows) => rows.length);
|
return query.get().then((rows) => rows.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<int> getRemainderCount() async {
|
Future<int> getRemainderCount(String userId) async {
|
||||||
final query = _db.localAlbumAssetEntity.selectOnly(distinct: true)
|
final query = _db.localAlbumAssetEntity.selectOnly(distinct: true)
|
||||||
..addColumns([_db.localAlbumAssetEntity.assetId])
|
..addColumns([_db.localAlbumAssetEntity.assetId])
|
||||||
..join([
|
..join([
|
||||||
|
|
@ -74,7 +74,8 @@ class DriftBackupRepository extends DriftDatabaseRepository {
|
||||||
..where(
|
..where(
|
||||||
_db.localAlbumEntity.backupSelection
|
_db.localAlbumEntity.backupSelection
|
||||||
.equalsValue(BackupSelection.selected) &
|
.equalsValue(BackupSelection.selected) &
|
||||||
_db.remoteAssetEntity.id.isNull() &
|
(_db.remoteAssetEntity.id.isNull() |
|
||||||
|
_db.remoteAssetEntity.ownerId.equals(userId).not()) &
|
||||||
_db.localAlbumAssetEntity.assetId
|
_db.localAlbumAssetEntity.assetId
|
||||||
.isNotInQuery(_getExcludedSubquery()),
|
.isNotInQuery(_getExcludedSubquery()),
|
||||||
);
|
);
|
||||||
|
|
@ -82,7 +83,7 @@ class DriftBackupRepository extends DriftDatabaseRepository {
|
||||||
return query.get().then((rows) => rows.length);
|
return query.get().then((rows) => rows.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<int> getBackupCount() async {
|
Future<int> getBackupCount(String userId) async {
|
||||||
final query = _db.localAlbumAssetEntity.selectOnly(distinct: true)
|
final query = _db.localAlbumAssetEntity.selectOnly(distinct: true)
|
||||||
..addColumns(
|
..addColumns(
|
||||||
[_db.localAlbumAssetEntity.assetId],
|
[_db.localAlbumAssetEntity.assetId],
|
||||||
|
|
@ -109,6 +110,7 @@ class DriftBackupRepository extends DriftDatabaseRepository {
|
||||||
_db.localAlbumEntity.backupSelection
|
_db.localAlbumEntity.backupSelection
|
||||||
.equalsValue(BackupSelection.selected) &
|
.equalsValue(BackupSelection.selected) &
|
||||||
_db.remoteAssetEntity.id.isNotNull() &
|
_db.remoteAssetEntity.id.isNotNull() &
|
||||||
|
_db.remoteAssetEntity.ownerId.equals(userId) &
|
||||||
_db.localAlbumAssetEntity.assetId
|
_db.localAlbumAssetEntity.assetId
|
||||||
.isNotInQuery(_getExcludedSubquery()),
|
.isNotInQuery(_getExcludedSubquery()),
|
||||||
);
|
);
|
||||||
|
|
@ -116,7 +118,7 @@ class DriftBackupRepository extends DriftDatabaseRepository {
|
||||||
return query.get().then((rows) => rows.length);
|
return query.get().then((rows) => rows.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<LocalAsset>> getCandidates() async {
|
Future<List<LocalAsset>> getCandidates(String userId) async {
|
||||||
final selectedAlbumIds = _db.localAlbumEntity.selectOnly(distinct: true)
|
final selectedAlbumIds = _db.localAlbumEntity.selectOnly(distinct: true)
|
||||||
..addColumns([_db.localAlbumEntity.id])
|
..addColumns([_db.localAlbumEntity.id])
|
||||||
..where(
|
..where(
|
||||||
|
|
@ -141,6 +143,7 @@ class DriftBackupRepository extends DriftDatabaseRepository {
|
||||||
..addColumns([_db.remoteAssetEntity.checksum])
|
..addColumns([_db.remoteAssetEntity.checksum])
|
||||||
..where(
|
..where(
|
||||||
_db.remoteAssetEntity.checksum.equalsExp(lae.checksum) &
|
_db.remoteAssetEntity.checksum.equalsExp(lae.checksum) &
|
||||||
|
_db.remoteAssetEntity.ownerId.equals(userId) &
|
||||||
lae.checksum.isNotNull(),
|
lae.checksum.isNotNull(),
|
||||||
),
|
),
|
||||||
) &
|
) &
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ import 'package:drift/drift.dart';
|
||||||
import 'package:drift_flutter/drift_flutter.dart';
|
import 'package:drift_flutter/drift_flutter.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:immich_mobile/domain/interfaces/db.interface.dart';
|
import 'package:immich_mobile/domain/interfaces/db.interface.dart';
|
||||||
import 'package:immich_mobile/infrastructure/entities/exif.entity.dart';
|
|
||||||
import 'package:immich_mobile/infrastructure/entities/asset_face.entity.dart';
|
import 'package:immich_mobile/infrastructure/entities/asset_face.entity.dart';
|
||||||
|
import 'package:immich_mobile/infrastructure/entities/exif.entity.dart';
|
||||||
import 'package:immich_mobile/infrastructure/entities/local_album.entity.dart';
|
import 'package:immich_mobile/infrastructure/entities/local_album.entity.dart';
|
||||||
import 'package:immich_mobile/infrastructure/entities/local_album_asset.entity.dart';
|
import 'package:immich_mobile/infrastructure/entities/local_album_asset.entity.dart';
|
||||||
import 'package:immich_mobile/infrastructure/entities/local_asset.entity.dart';
|
import 'package:immich_mobile/infrastructure/entities/local_asset.entity.dart';
|
||||||
|
|
@ -97,7 +97,9 @@ class Drift extends $Drift implements IDatabaseRepository {
|
||||||
await m.alterTable(TableMigration(v3.stackEntity));
|
await m.alterTable(TableMigration(v3.stackEntity));
|
||||||
},
|
},
|
||||||
from3To4: (m, v4) async {
|
from3To4: (m, v4) async {
|
||||||
|
// Thumbnail path column got removed from person_entity
|
||||||
await m.alterTable(TableMigration(v4.personEntity));
|
await m.alterTable(TableMigration(v4.personEntity));
|
||||||
|
// asset_face_entity is added
|
||||||
await m.create(v4.assetFaceEntity);
|
await m.create(v4.assetFaceEntity);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
|
|
@ -32,49 +32,21 @@ class RemoteAssetRepository extends DriftDatabaseRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
Stream<RemoteAsset?> watchAsset(String id) {
|
Stream<RemoteAsset?> watchAsset(String id) {
|
||||||
final stackCountRef = _db.stackEntity.id.count();
|
|
||||||
|
|
||||||
final query = _db.remoteAssetEntity.select().addColumns([
|
final query = _db.remoteAssetEntity.select().addColumns([
|
||||||
_db.localAssetEntity.id,
|
_db.localAssetEntity.id,
|
||||||
_db.stackEntity.primaryAssetId,
|
|
||||||
stackCountRef,
|
|
||||||
]).join([
|
]).join([
|
||||||
leftOuterJoin(
|
leftOuterJoin(
|
||||||
_db.localAssetEntity,
|
_db.localAssetEntity,
|
||||||
_db.remoteAssetEntity.checksum.equalsExp(_db.localAssetEntity.checksum),
|
_db.remoteAssetEntity.checksum.equalsExp(_db.localAssetEntity.checksum),
|
||||||
useColumns: false,
|
useColumns: false,
|
||||||
),
|
),
|
||||||
leftOuterJoin(
|
|
||||||
_db.stackEntity,
|
|
||||||
_db.stackEntity.primaryAssetId.equalsExp(_db.remoteAssetEntity.id),
|
|
||||||
useColumns: false,
|
|
||||||
),
|
|
||||||
leftOuterJoin(
|
|
||||||
_db.remoteAssetEntity.createAlias('stacked_assets'),
|
|
||||||
_db.stackEntity.id.equalsExp(
|
|
||||||
_db.remoteAssetEntity.createAlias('stacked_assets').stackId,
|
|
||||||
),
|
|
||||||
useColumns: false,
|
|
||||||
),
|
|
||||||
])
|
])
|
||||||
..where(_db.remoteAssetEntity.id.equals(id))
|
..where(_db.remoteAssetEntity.id.equals(id))
|
||||||
..groupBy([
|
|
||||||
_db.remoteAssetEntity.id,
|
|
||||||
_db.localAssetEntity.id,
|
|
||||||
_db.stackEntity.primaryAssetId,
|
|
||||||
])
|
|
||||||
..limit(1);
|
..limit(1);
|
||||||
|
|
||||||
return query.map((row) {
|
return query.map((row) {
|
||||||
final asset = row.readTable(_db.remoteAssetEntity).toDto();
|
final asset = row.readTable(_db.remoteAssetEntity).toDto();
|
||||||
final primaryAssetId = row.read(_db.stackEntity.primaryAssetId);
|
return asset.copyWith(localId: row.read(_db.localAssetEntity.id));
|
||||||
final stackCount =
|
|
||||||
primaryAssetId == id ? (row.read(stackCountRef) ?? 0) : 0;
|
|
||||||
|
|
||||||
return asset.copyWith(
|
|
||||||
localId: row.read(_db.localAssetEntity.id),
|
|
||||||
stackCount: stackCount,
|
|
||||||
);
|
|
||||||
}).watchSingleOrNull();
|
}).watchSingleOrNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ class DriftTimelineRepository extends DriftDatabaseRepository {
|
||||||
required int count,
|
required int count,
|
||||||
}) {
|
}) {
|
||||||
return _db.mergedAssetDrift
|
return _db.mergedAssetDrift
|
||||||
.mergedAsset(userIds, limit: Limit(count, offset))
|
.mergedAsset(userIds, limit: (_) => Limit(count, offset))
|
||||||
.map(
|
.map(
|
||||||
(row) => row.remoteId != null && row.ownerId != null
|
(row) => row.remoteId != null && row.ownerId != null
|
||||||
? RemoteAsset(
|
? RemoteAsset(
|
||||||
|
|
@ -90,7 +90,6 @@ class DriftTimelineRepository extends DriftDatabaseRepository {
|
||||||
durationInSeconds: row.durationInSeconds,
|
durationInSeconds: row.durationInSeconds,
|
||||||
livePhotoVideoId: row.livePhotoVideoId,
|
livePhotoVideoId: row.livePhotoVideoId,
|
||||||
stackId: row.stackId,
|
stackId: row.stackId,
|
||||||
stackCount: row.stackCount,
|
|
||||||
)
|
)
|
||||||
: LocalAsset(
|
: LocalAsset(
|
||||||
id: row.localId!,
|
id: row.localId!,
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import 'package:immich_mobile/extensions/translate_extensions.dart';
|
||||||
import 'package:immich_mobile/presentation/widgets/backup/backup_toggle_button.widget.dart';
|
import 'package:immich_mobile/presentation/widgets/backup/backup_toggle_button.widget.dart';
|
||||||
import 'package:immich_mobile/providers/backup/backup_album.provider.dart';
|
import 'package:immich_mobile/providers/backup/backup_album.provider.dart';
|
||||||
import 'package:immich_mobile/providers/backup/drift_backup.provider.dart';
|
import 'package:immich_mobile/providers/backup/drift_backup.provider.dart';
|
||||||
|
import 'package:immich_mobile/providers/user.provider.dart';
|
||||||
import 'package:immich_mobile/routing/router.dart';
|
import 'package:immich_mobile/routing/router.dart';
|
||||||
import 'package:immich_mobile/widgets/backup/backup_info_card.dart';
|
import 'package:immich_mobile/widgets/backup/backup_info_card.dart';
|
||||||
|
|
||||||
|
|
@ -24,12 +25,24 @@ class _DriftBackupPageState extends ConsumerState<DriftBackupPage> {
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
ref.read(driftBackupProvider.notifier).getBackupStatus();
|
final currentUser = ref.read(currentUserProvider);
|
||||||
|
if (currentUser == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ref.read(driftBackupProvider.notifier).getBackupStatus(currentUser.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> startBackup() async {
|
Future<void> startBackup() async {
|
||||||
await ref.read(driftBackupProvider.notifier).getBackupStatus();
|
final currentUser = ref.read(currentUserProvider);
|
||||||
await ref.read(driftBackupProvider.notifier).backup();
|
if (currentUser == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await ref
|
||||||
|
.read(driftBackupProvider.notifier)
|
||||||
|
.getBackupStatus(currentUser.id);
|
||||||
|
await ref.read(driftBackupProvider.notifier).backup(currentUser.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> stopBackup() async {
|
Future<void> stopBackup() async {
|
||||||
|
|
@ -207,7 +220,13 @@ class _BackupAlbumSelectionCard extends ConsumerWidget {
|
||||||
trailing: ElevatedButton(
|
trailing: ElevatedButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
await context.pushRoute(const DriftBackupAlbumSelectionRoute());
|
await context.pushRoute(const DriftBackupAlbumSelectionRoute());
|
||||||
ref.read(driftBackupProvider.notifier).getBackupStatus();
|
final currentUser = ref.read(currentUserProvider);
|
||||||
|
if (currentUser == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ref
|
||||||
|
.read(driftBackupProvider.notifier)
|
||||||
|
.getBackupStatus(currentUser.id);
|
||||||
},
|
},
|
||||||
child: const Text(
|
child: const Text(
|
||||||
"select",
|
"select",
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,17 @@ import 'package:auto_route/auto_route.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:immich_mobile/domain/models/album/local_album.model.dart';
|
import 'package:immich_mobile/domain/models/album/local_album.model.dart';
|
||||||
|
|
||||||
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
||||||
import 'package:immich_mobile/extensions/translate_extensions.dart';
|
import 'package:immich_mobile/extensions/translate_extensions.dart';
|
||||||
import 'package:immich_mobile/providers/album/album.provider.dart';
|
import 'package:immich_mobile/providers/album/album.provider.dart';
|
||||||
|
import 'package:immich_mobile/providers/app_settings.provider.dart';
|
||||||
import 'package:immich_mobile/providers/backup/backup_album.provider.dart';
|
import 'package:immich_mobile/providers/backup/backup_album.provider.dart';
|
||||||
import 'package:immich_mobile/providers/backup/drift_backup.provider.dart';
|
import 'package:immich_mobile/providers/backup/drift_backup.provider.dart';
|
||||||
|
import 'package:immich_mobile/providers/user.provider.dart';
|
||||||
import 'package:immich_mobile/services/app_settings.service.dart';
|
import 'package:immich_mobile/services/app_settings.service.dart';
|
||||||
import 'package:immich_mobile/providers/app_settings.provider.dart';
|
|
||||||
import 'package:immich_mobile/widgets/backup/drift_album_info_list_tile.dart';
|
import 'package:immich_mobile/widgets/backup/drift_album_info_list_tile.dart';
|
||||||
import 'package:immich_mobile/widgets/settings/settings_switch_list_tile.dart';
|
|
||||||
import 'package:immich_mobile/widgets/common/search_field.dart';
|
import 'package:immich_mobile/widgets/common/search_field.dart';
|
||||||
|
import 'package:immich_mobile/widgets/settings/settings_switch_list_tile.dart';
|
||||||
|
|
||||||
@RoutePage()
|
@RoutePage()
|
||||||
class DriftBackupAlbumSelectionPage extends ConsumerStatefulWidget {
|
class DriftBackupAlbumSelectionPage extends ConsumerStatefulWidget {
|
||||||
|
|
@ -92,7 +92,15 @@ class _DriftBackupAlbumSelectionPageState
|
||||||
if (didPop && !_hasPopped) {
|
if (didPop && !_hasPopped) {
|
||||||
_hasPopped = true;
|
_hasPopped = true;
|
||||||
|
|
||||||
await ref.read(driftBackupProvider.notifier).getBackupStatus();
|
super.initState();
|
||||||
|
final currentUser = ref.read(currentUserProvider);
|
||||||
|
if (currentUser == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await ref
|
||||||
|
.read(driftBackupProvider.notifier)
|
||||||
|
.getBackupStatus(currentUser.id);
|
||||||
final currentTotalAssetCount =
|
final currentTotalAssetCount =
|
||||||
ref.read(driftBackupProvider.select((p) => p.totalCount));
|
ref.read(driftBackupProvider.select((p) => p.totalCount));
|
||||||
|
|
||||||
|
|
@ -107,7 +115,7 @@ class _DriftBackupAlbumSelectionPageState
|
||||||
final backupNotifier = ref.read(driftBackupProvider.notifier);
|
final backupNotifier = ref.read(driftBackupProvider.notifier);
|
||||||
|
|
||||||
backupNotifier.cancel().then((_) {
|
backupNotifier.cancel().then((_) {
|
||||||
backupNotifier.backup();
|
backupNotifier.backup(currentUser.id);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import 'package:immich_mobile/providers/infrastructure/album.provider.dart';
|
||||||
import 'package:immich_mobile/providers/search/search_input_focus.provider.dart';
|
import 'package:immich_mobile/providers/search/search_input_focus.provider.dart';
|
||||||
import 'package:immich_mobile/providers/tab.provider.dart';
|
import 'package:immich_mobile/providers/tab.provider.dart';
|
||||||
import 'package:immich_mobile/providers/timeline/multiselect.provider.dart';
|
import 'package:immich_mobile/providers/timeline/multiselect.provider.dart';
|
||||||
|
import 'package:immich_mobile/providers/user.provider.dart';
|
||||||
import 'package:immich_mobile/providers/websocket.provider.dart';
|
import 'package:immich_mobile/providers/websocket.provider.dart';
|
||||||
import 'package:immich_mobile/routing/router.dart';
|
import 'package:immich_mobile/routing/router.dart';
|
||||||
import 'package:immich_mobile/services/app_settings.service.dart';
|
import 'package:immich_mobile/services/app_settings.service.dart';
|
||||||
|
|
@ -38,7 +39,14 @@ class _TabShellPageState extends ConsumerState<TabShellPage> {
|
||||||
|
|
||||||
await runNewSync(ref, full: true).then((_) async {
|
await runNewSync(ref, full: true).then((_) async {
|
||||||
if (isEnableBackup) {
|
if (isEnableBackup) {
|
||||||
await ref.read(driftBackupProvider.notifier).handleBackupResume();
|
final currentUser = ref.read(currentUserProvider);
|
||||||
|
if (currentUser == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await ref
|
||||||
|
.read(driftBackupProvider.notifier)
|
||||||
|
.handleBackupResume(currentUser.id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,7 @@ class StackChildrenNotifier
|
||||||
extends AutoDisposeFamilyAsyncNotifier<List<RemoteAsset>, BaseAsset?> {
|
extends AutoDisposeFamilyAsyncNotifier<List<RemoteAsset>, BaseAsset?> {
|
||||||
@override
|
@override
|
||||||
Future<List<RemoteAsset>> build(BaseAsset? asset) async {
|
Future<List<RemoteAsset>> build(BaseAsset? asset) async {
|
||||||
if (asset == null ||
|
if (asset == null || asset is! RemoteAsset || asset.stackId == null) {
|
||||||
asset is! RemoteAsset ||
|
|
||||||
asset.stackId == null ||
|
|
||||||
// The stackCount check is to ensure we only fetch stacks for timelines that have stacks
|
|
||||||
asset.stackCount == 0) {
|
|
||||||
return const [];
|
return const [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ class ThumbnailTile extends ConsumerWidget {
|
||||||
: const BoxDecoration();
|
: const BoxDecoration();
|
||||||
|
|
||||||
final hasStack =
|
final hasStack =
|
||||||
asset is RemoteAsset && (asset as RemoteAsset).stackCount > 0;
|
asset is RemoteAsset && (asset as RemoteAsset).stackId != null;
|
||||||
|
|
||||||
return Stack(
|
return Stack(
|
||||||
children: [
|
children: [
|
||||||
|
|
@ -86,9 +86,7 @@ class ThumbnailTile extends ConsumerWidget {
|
||||||
right: 10.0,
|
right: 10.0,
|
||||||
top: asset.isVideo ? 24.0 : 6.0,
|
top: asset.isVideo ? 24.0 : 6.0,
|
||||||
),
|
),
|
||||||
child: _StackIndicator(
|
child: const _TileOverlayIcon(Icons.burst_mode_rounded),
|
||||||
stackCount: (asset as RemoteAsset).stackCount,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (asset.isVideo)
|
if (asset.isVideo)
|
||||||
|
|
@ -198,40 +196,6 @@ class _SelectionIndicator extends StatelessWidget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _StackIndicator extends StatelessWidget {
|
|
||||||
final int stackCount;
|
|
||||||
|
|
||||||
const _StackIndicator({required this.stackCount});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Row(
|
|
||||||
spacing: 3,
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
mainAxisAlignment: MainAxisAlignment.end,
|
|
||||||
// CrossAxisAlignment.start looks more centered vertically than CrossAxisAlignment.center
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
stackCount.toString(),
|
|
||||||
style: const TextStyle(
|
|
||||||
color: Colors.white,
|
|
||||||
fontSize: 12,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
shadows: [
|
|
||||||
Shadow(
|
|
||||||
blurRadius: 5.0,
|
|
||||||
color: Color.fromRGBO(0, 0, 0, 0.6),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const _TileOverlayIcon(Icons.burst_mode_rounded),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class _VideoIndicator extends StatelessWidget {
|
class _VideoIndicator extends StatelessWidget {
|
||||||
final Duration duration;
|
final Duration duration;
|
||||||
const _VideoIndicator(this.duration);
|
const _VideoIndicator(this.duration);
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ import 'package:immich_mobile/providers/memory.provider.dart';
|
||||||
import 'package:immich_mobile/providers/notification_permission.provider.dart';
|
import 'package:immich_mobile/providers/notification_permission.provider.dart';
|
||||||
import 'package:immich_mobile/providers/server_info.provider.dart';
|
import 'package:immich_mobile/providers/server_info.provider.dart';
|
||||||
import 'package:immich_mobile/providers/tab.provider.dart';
|
import 'package:immich_mobile/providers/tab.provider.dart';
|
||||||
|
import 'package:immich_mobile/providers/user.provider.dart';
|
||||||
import 'package:immich_mobile/providers/websocket.provider.dart';
|
import 'package:immich_mobile/providers/websocket.provider.dart';
|
||||||
import 'package:immich_mobile/services/app_settings.service.dart';
|
import 'package:immich_mobile/services/app_settings.service.dart';
|
||||||
import 'package:immich_mobile/services/background.service.dart';
|
import 'package:immich_mobile/services/background.service.dart';
|
||||||
|
|
@ -110,7 +111,14 @@ class AppLifeCycleNotifier extends StateNotifier<AppLifeCycleEnum> {
|
||||||
.getSetting(AppSettingsEnum.enableBackup);
|
.getSetting(AppSettingsEnum.enableBackup);
|
||||||
|
|
||||||
if (isEnableBackup) {
|
if (isEnableBackup) {
|
||||||
await _ref.read(driftBackupProvider.notifier).handleBackupResume();
|
final currentUser = _ref.read(currentUserProvider);
|
||||||
|
if (currentUser == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await _ref
|
||||||
|
.read(driftBackupProvider.notifier)
|
||||||
|
.handleBackupResume(currentUser.id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (e, stackTrace) {
|
} catch (e, stackTrace) {
|
||||||
|
|
|
||||||
|
|
@ -329,11 +329,11 @@ class ExpBackupNotifier extends StateNotifier<DriftBackupState> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> getBackupStatus() async {
|
Future<void> getBackupStatus(String userId) async {
|
||||||
final [totalCount, backupCount, remainderCount] = await Future.wait([
|
final [totalCount, backupCount, remainderCount] = await Future.wait([
|
||||||
_backupService.getTotalCount(),
|
_backupService.getTotalCount(),
|
||||||
_backupService.getBackupCount(),
|
_backupService.getBackupCount(userId),
|
||||||
_backupService.getRemainderCount(),
|
_backupService.getRemainderCount(userId),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
state = state.copyWith(
|
state = state.copyWith(
|
||||||
|
|
@ -343,8 +343,8 @@ class ExpBackupNotifier extends StateNotifier<DriftBackupState> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> backup() {
|
Future<void> backup(String userId) {
|
||||||
return _backupService.backup(_updateEnqueueCount);
|
return _backupService.backup(userId, _updateEnqueueCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _updateEnqueueCount(EnqueueStatus status) {
|
void _updateEnqueueCount(EnqueueStatus status) {
|
||||||
|
|
@ -379,11 +379,11 @@ class ExpBackupNotifier extends StateNotifier<DriftBackupState> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> handleBackupResume() async {
|
Future<void> handleBackupResume(String userId) async {
|
||||||
final tasks = await FileDownloader().allTasks(group: kBackupGroup);
|
final tasks = await FileDownloader().allTasks(group: kBackupGroup);
|
||||||
if (tasks.isEmpty) {
|
if (tasks.isEmpty) {
|
||||||
// Start a new backup queue
|
// Start a new backup queue
|
||||||
await backup();
|
await backup(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
debugPrint("Tasks to resume: ${tasks.length}");
|
debugPrint("Tasks to resume: ${tasks.length}");
|
||||||
|
|
|
||||||
|
|
@ -48,20 +48,21 @@ class DriftBackupService {
|
||||||
return _backupRepository.getTotalCount();
|
return _backupRepository.getTotalCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<int> getRemainderCount() {
|
Future<int> getRemainderCount(String userId) {
|
||||||
return _backupRepository.getRemainderCount();
|
return _backupRepository.getRemainderCount(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<int> getBackupCount() {
|
Future<int> getBackupCount(String userId) {
|
||||||
return _backupRepository.getBackupCount();
|
return _backupRepository.getBackupCount(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> backup(
|
Future<void> backup(
|
||||||
|
String userId,
|
||||||
void Function(EnqueueStatus status) onEnqueueTasks,
|
void Function(EnqueueStatus status) onEnqueueTasks,
|
||||||
) async {
|
) async {
|
||||||
shouldCancel = false;
|
shouldCancel = false;
|
||||||
|
|
||||||
final candidates = await _backupRepository.getCandidates();
|
final candidates = await _backupRepository.getCandidates(userId);
|
||||||
if (candidates.isEmpty) {
|
if (candidates.isEmpty) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
BIN
mobile/test/drift/main/generated/schema_v4.dart
generated
BIN
mobile/test/drift/main/generated/schema_v4.dart
generated
Binary file not shown.
Loading…
Reference in a new issue