Skip to content

Commit b6ccf75

Browse files
committed
feat: asset count
1 parent 9a1d72e commit b6ccf75

File tree

9 files changed

+474
-165
lines changed

9 files changed

+474
-165
lines changed

mobile/lib/domain/models/album/album.model.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class Album {
2121
final String? thumbnailAssetId;
2222
final bool isActivityEnabled;
2323
final AlbumAssetOrder order;
24+
final int assetCount;
2425

2526
const Album({
2627
required this.id,
@@ -32,6 +33,7 @@ class Album {
3233
this.thumbnailAssetId,
3334
required this.isActivityEnabled,
3435
required this.order,
36+
required this.assetCount,
3537
});
3638

3739
@override
@@ -46,6 +48,7 @@ class Album {
4648
isActivityEnabled: $isActivityEnabled,
4749
order: $order,
4850
thumbnailAssetId: ${thumbnailAssetId ?? "<NA>"}
51+
assetCount: $assetCount
4952
}''';
5053
}
5154

@@ -61,7 +64,8 @@ class Album {
6164
updatedAt == other.updatedAt &&
6265
thumbnailAssetId == other.thumbnailAssetId &&
6366
isActivityEnabled == other.isActivityEnabled &&
64-
order == other.order;
67+
order == other.order &&
68+
assetCount == other.assetCount;
6569
}
6670

6771
@override
@@ -74,6 +78,7 @@ class Album {
7478
updatedAt.hashCode ^
7579
thumbnailAssetId.hashCode ^
7680
isActivityEnabled.hashCode ^
77-
order.hashCode;
81+
order.hashCode ^
82+
assetCount.hashCode;
7883
}
7984
}

mobile/lib/domain/services/sync_stream.service.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ class SyncStreamService {
5151

5252
final type = batch.first.type;
5353
await _handleSyncData(type, batch.map((e) => e.data));
54-
print("Processed ${batch.last.ack.length} events of type $type");
5554
await _syncApiRepository.ack([batch.last.ack]);
5655
batch.clear();
5756
}

mobile/lib/infrastructure/repositories/remote_album.repository.dart

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,43 @@ class DriftRemoteAlbumRepository extends DriftDatabaseRepository {
1010
const DriftRemoteAlbumRepository(this._db) : super(_db);
1111

1212
Future<List<Album>> getAll({Set<SortRemoteAlbumsBy> sortBy = const {}}) {
13-
final query = _db.remoteAlbumEntity.select();
13+
final assetCount = _db.remoteAlbumAssetEntity.assetId.count();
14+
15+
final query = _db.remoteAlbumEntity.select().join([
16+
leftOuterJoin(
17+
_db.remoteAlbumAssetEntity,
18+
_db.remoteAlbumAssetEntity.albumId.equalsExp(_db.remoteAlbumEntity.id),
19+
useColumns: false,
20+
),
21+
]);
22+
query
23+
..addColumns([assetCount])
24+
..groupBy([_db.remoteAlbumEntity.id]);
1425

1526
if (sortBy.isNotEmpty) {
16-
final orderings = <OrderClauseGenerator<$RemoteAlbumEntityTable>>[];
27+
final orderings = <OrderingTerm>[];
1728
for (final sort in sortBy) {
1829
orderings.add(
1930
switch (sort) {
20-
SortRemoteAlbumsBy.id => (row) => OrderingTerm.asc(row.id),
31+
SortRemoteAlbumsBy.id => OrderingTerm.asc(_db.remoteAssetEntity.id),
2132
},
2233
);
2334
}
2435
query.orderBy(orderings);
2536
}
2637

27-
return query.map((row) => row.toDto()).get();
38+
return query
39+
.map(
40+
(row) => row
41+
.readTable(_db.remoteAlbumEntity)
42+
.toDto(assetCount: row.read(assetCount) ?? 0),
43+
)
44+
.get();
2845
}
2946
}
3047

3148
extension on RemoteAlbumEntityData {
32-
Album toDto() {
49+
Album toDto({int assetCount = 0}) {
3350
return Album(
3451
id: id,
3552
name: name,
@@ -40,6 +57,7 @@ extension on RemoteAlbumEntityData {
4057
thumbnailAssetId: thumbnailAssetId,
4158
isActivityEnabled: isActivityEnabled,
4259
order: order,
60+
assetCount: assetCount,
4361
);
4462
}
4563
}

mobile/lib/infrastructure/repositories/sync_api.repository.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class SyncApiRepository {
1515
SyncApiRepository(this._api);
1616

1717
Future<void> ack(List<String> data) {
18-
print("Sending sync acks: $data");
1918
return _api.syncApi.sendSyncAck(SyncAckSetDto(acks: data));
2019
}
2120

0 commit comments

Comments
 (0)