From 11df8d2491de68a95676990edafc4a3c7831b9f3 Mon Sep 17 00:00:00 2001 From: Penlane Date: Sat, 15 Aug 2026 13:50:24 +0200 Subject: [PATCH] refactor(mobile): simplify _localOnlyFilter, introduce query helper --- .../repositories/timeline.repository.dart | 49 +++++++------------ 1 file changed, 19 insertions(+), 30 deletions(-) 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();