diff --git a/mobile/lib/infrastructure/repositories/timeline.repository.dart b/mobile/lib/infrastructure/repositories/timeline.repository.dart index 0cd1e06594..6ac6b4cc73 100644 --- a/mobile/lib/infrastructure/repositories/timeline.repository.dart +++ b/mobile/lib/infrastructure/repositories/timeline.repository.dart @@ -127,39 +127,28 @@ class DriftTimelineRepository extends DriftDatabaseRepository { origin: TimelineOrigin.main, ); - Expression _localOnlyFilter() { + Expression _inAlbumWithBackupSelection(BackupSelection selection) { return existsQuery( - _db.localAlbumAssetEntity.selectOnly() - ..addColumns([_db.localAlbumAssetEntity.assetId]) - ..join([ - innerJoin( - _db.localAlbumEntity, - _db.localAlbumEntity.id.equalsExp(_db.localAlbumAssetEntity.albumId), - useColumns: false, - ), - ]) - ..where( - _db.localAlbumAssetEntity.assetId.equalsExp(_db.localAssetEntity.id) & - _db.localAlbumEntity.backupSelection.equalsValue(BackupSelection.selected), - ), - ) & - existsQuery( - _db.localAlbumAssetEntity.selectOnly() - ..addColumns([_db.localAlbumAssetEntity.assetId]) - ..join([ - innerJoin( - _db.localAlbumEntity, - _db.localAlbumEntity.id.equalsExp(_db.localAlbumAssetEntity.albumId), - useColumns: false, - ), - ]) - ..where( - _db.localAlbumAssetEntity.assetId.equalsExp(_db.localAssetEntity.id) & - _db.localAlbumEntity.backupSelection.equalsValue(BackupSelection.excluded), - ), - ).not(); + _db.localAlbumAssetEntity.selectOnly() + ..addColumns([_db.localAlbumAssetEntity.assetId]) + ..join([ + innerJoin( + _db.localAlbumEntity, + _db.localAlbumEntity.id.equalsExp(_db.localAlbumAssetEntity.albumId), + useColumns: false, + ), + ]) + ..where( + _db.localAlbumAssetEntity.assetId.equalsExp(_db.localAssetEntity.id) & + _db.localAlbumEntity.backupSelection.equalsValue(selection), + ), + ); } + Expression _localOnlyFilter() => + _inAlbumWithBackupSelection(BackupSelection.selected) & + _inAlbumWithBackupSelection(BackupSelection.excluded).not(); + Stream> _watchLocalOnlyBucket({GroupAssetsBy groupBy = GroupAssetsBy.day}) { if (groupBy == GroupAssetsBy.none) { return _db.localAssetEntity.count(where: (_) => _localOnlyFilter()).map(_generateBuckets).watchSingle();