feat(mobile): lazy loading of assets (#2413)

This commit is contained in:
Fynn Petersen-Frey
2023-05-17 19:36:02 +02:00
committed by GitHub
parent 93863b0629
commit 0dde76bbbc
54 changed files with 1494 additions and 2328 deletions

View File

@@ -1,4 +1,5 @@
import 'package:flutter/cupertino.dart';
import 'package:immich_mobile/modules/home/ui/asset_grid/asset_grid_data_structure.dart';
import 'package:immich_mobile/shared/models/asset.dart';
import 'package:immich_mobile/shared/models/store.dart';
import 'package:immich_mobile/shared/models/user.dart';
@@ -34,10 +35,10 @@ class Album {
final IsarLinks<User> sharedUsers = IsarLinks<User>();
final IsarLinks<Asset> assets = IsarLinks<Asset>();
List<Asset> _sortedAssets = [];
RenderList _renderList = RenderList.empty();
@ignore
List<Asset> get sortedAssets => _sortedAssets;
RenderList get renderList => _renderList;
@ignore
bool get isRemote => remoteId != null;
@@ -69,8 +70,14 @@ class Album {
return name.join(' ');
}
Future<void> loadSortedAssets() async {
_sortedAssets = await assets.filter().sortByFileCreatedAt().findAll();
Stream<void> watchRenderList(GroupAssetsBy groupAssetsBy) async* {
final query = assets.filter().sortByFileCreatedAt();
_renderList = await RenderList.fromQuery(query, groupAssetsBy);
yield _renderList;
await for (final _ in query.watchLazy()) {
_renderList = await RenderList.fromQuery(query, groupAssetsBy);
yield _renderList;
}
}
@override

View File

@@ -225,7 +225,6 @@ class Asset {
a.isLocal && !isLocal ||
width == null && a.width != null ||
height == null && a.height != null ||
exifInfo == null && a.exifInfo != null ||
livePhotoVideoId == null && a.livePhotoVideoId != null ||
!isRemote && a.isRemote && isFavorite != a.isFavorite ||
!isRemote && a.isRemote && isArchived != a.isArchived;

View File

@@ -114,6 +114,45 @@ class ExifInfo {
country: country ?? this.country,
description: description ?? this.description,
);
@override
bool operator ==(other) {
if (other is! ExifInfo) return false;
return id == other.id &&
fileSize == other.fileSize &&
make == other.make &&
model == other.model &&
lens == other.lens &&
f == other.f &&
mm == other.mm &&
iso == other.iso &&
exposureSeconds == other.exposureSeconds &&
lat == other.lat &&
long == other.long &&
city == other.city &&
state == other.state &&
country == other.country &&
description == other.description;
}
@override
@ignore
int get hashCode =>
id.hashCode ^
fileSize.hashCode ^
make.hashCode ^
model.hashCode ^
lens.hashCode ^
f.hashCode ^
mm.hashCode ^
iso.hashCode ^
exposureSeconds.hashCode ^
lat.hashCode ^
long.hashCode ^
city.hashCode ^
state.hashCode ^
country.hashCode ^
description.hashCode;
}
double? _exposureTimeToSeconds(String? s) {

View File

@@ -35,6 +35,10 @@ class Store {
return value;
}
/// Watches a specific key for changes
static Stream<T?> watch<T>(StoreKey<T> key) =>
_db.storeValues.watchObject(key.id).map((e) => e?._extract(key));
/// Returns the stored value for the given key (possibly null)
static T? tryGet<T>(StoreKey<T> key) => _cache[key.id];