mirror of
https://github.com/immich-app/immich.git
synced 2025-01-04 02:46:47 +01:00
fix(mobile): speed up RenderList creation for timeline (#4103)
Co-authored-by: Alex <alex.tran1502@gmail.com>
This commit is contained in:
parent
a937efe719
commit
098ab9eae5
7 changed files with 19 additions and 17 deletions
|
@ -13,8 +13,9 @@ final archiveProvider = StreamProvider<RenderList>((ref) async* {
|
||||||
final query = ref
|
final query = ref
|
||||||
.watch(dbProvider)
|
.watch(dbProvider)
|
||||||
.assets
|
.assets
|
||||||
|
.where()
|
||||||
|
.ownerIdEqualToAnyChecksum(user.isarId)
|
||||||
.filter()
|
.filter()
|
||||||
.ownerIdEqualTo(user.isarId)
|
|
||||||
.isArchivedEqualTo(true)
|
.isArchivedEqualTo(true)
|
||||||
.sortByFileCreatedAt();
|
.sortByFileCreatedAt();
|
||||||
final settings = ref.watch(appSettingsServiceProvider);
|
final settings = ref.watch(appSettingsServiceProvider);
|
||||||
|
|
|
@ -13,8 +13,9 @@ final favoriteAssetsProvider = StreamProvider<RenderList>((ref) async* {
|
||||||
final query = ref
|
final query = ref
|
||||||
.watch(dbProvider)
|
.watch(dbProvider)
|
||||||
.assets
|
.assets
|
||||||
|
.where()
|
||||||
|
.ownerIdEqualToAnyChecksum(user.isarId)
|
||||||
.filter()
|
.filter()
|
||||||
.ownerIdEqualTo(user.isarId)
|
|
||||||
.isFavoriteEqualTo(true)
|
.isFavoriteEqualTo(true)
|
||||||
.sortByFileCreatedAt();
|
.sortByFileCreatedAt();
|
||||||
final settings = ref.watch(appSettingsServiceProvider);
|
final settings = ref.watch(appSettingsServiceProvider);
|
||||||
|
|
|
@ -142,7 +142,7 @@ class RenderList {
|
||||||
) async {
|
) async {
|
||||||
final List<RenderAssetGridElement> elements = [];
|
final List<RenderAssetGridElement> elements = [];
|
||||||
|
|
||||||
const pageSize = 500;
|
const pageSize = 50000;
|
||||||
const sectionSize = 60; // divides evenly by 2,3,4,5,6
|
const sectionSize = 60; // divides evenly by 2,3,4,5,6
|
||||||
|
|
||||||
if (groupBy == GroupAssetsBy.none) {
|
if (groupBy == GroupAssetsBy.none) {
|
||||||
|
|
|
@ -100,12 +100,6 @@ class Asset {
|
||||||
|
|
||||||
/// stores the raw SHA1 bytes as a base64 String
|
/// stores the raw SHA1 bytes as a base64 String
|
||||||
/// because Isar cannot sort lists of byte arrays
|
/// because Isar cannot sort lists of byte arrays
|
||||||
@Index(
|
|
||||||
unique: true,
|
|
||||||
replace: false,
|
|
||||||
type: IndexType.hash,
|
|
||||||
composite: [CompositeIndex("ownerId")],
|
|
||||||
)
|
|
||||||
String checksum;
|
String checksum;
|
||||||
|
|
||||||
@Index(unique: false, replace: false, type: IndexType.hash)
|
@Index(unique: false, replace: false, type: IndexType.hash)
|
||||||
|
@ -114,6 +108,11 @@ class Asset {
|
||||||
@Index(unique: false, replace: false, type: IndexType.hash)
|
@Index(unique: false, replace: false, type: IndexType.hash)
|
||||||
String? localId;
|
String? localId;
|
||||||
|
|
||||||
|
@Index(
|
||||||
|
unique: true,
|
||||||
|
replace: false,
|
||||||
|
composite: [CompositeIndex("checksum", type: IndexType.hash)],
|
||||||
|
)
|
||||||
int ownerId;
|
int ownerId;
|
||||||
|
|
||||||
DateTime fileCreatedAt;
|
DateTime fileCreatedAt;
|
||||||
|
|
Binary file not shown.
|
@ -186,8 +186,9 @@ final assetsProvider =
|
||||||
final query = ref
|
final query = ref
|
||||||
.watch(dbProvider)
|
.watch(dbProvider)
|
||||||
.assets
|
.assets
|
||||||
|
.where()
|
||||||
|
.ownerIdEqualToAnyChecksum(userId)
|
||||||
.filter()
|
.filter()
|
||||||
.ownerIdEqualTo(userId)
|
|
||||||
.isArchivedEqualTo(false)
|
.isArchivedEqualTo(false)
|
||||||
.sortByFileCreatedAtDesc();
|
.sortByFileCreatedAtDesc();
|
||||||
final settings = ref.watch(appSettingsServiceProvider);
|
final settings = ref.watch(appSettingsServiceProvider);
|
||||||
|
|
|
@ -123,7 +123,7 @@ class SyncService {
|
||||||
/// Syncs a new asset to the db. Returns `true` if successful
|
/// Syncs a new asset to the db. Returns `true` if successful
|
||||||
Future<bool> _syncNewAssetToDb(Asset a) async {
|
Future<bool> _syncNewAssetToDb(Asset a) async {
|
||||||
final Asset? inDb =
|
final Asset? inDb =
|
||||||
await _db.assets.getByChecksumOwnerId(a.checksum, a.ownerId);
|
await _db.assets.getByOwnerIdChecksum(a.ownerId, a.checksum);
|
||||||
if (inDb != null) {
|
if (inDb != null) {
|
||||||
// unify local/remote assets by replacing the
|
// unify local/remote assets by replacing the
|
||||||
// local-only asset in the DB with a local&remote asset
|
// local-only asset in the DB with a local&remote asset
|
||||||
|
@ -195,8 +195,8 @@ class SyncService {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final List<Asset> inDb = await _db.assets
|
final List<Asset> inDb = await _db.assets
|
||||||
.filter()
|
.where()
|
||||||
.ownerIdEqualTo(user.isarId)
|
.ownerIdEqualToAnyChecksum(user.isarId)
|
||||||
.sortByChecksum()
|
.sortByChecksum()
|
||||||
.findAll();
|
.findAll();
|
||||||
assert(inDb.isSorted(Asset.compareByChecksum), "inDb not sorted!");
|
assert(inDb.isSorted(Asset.compareByChecksum), "inDb not sorted!");
|
||||||
|
@ -638,9 +638,9 @@ class SyncService {
|
||||||
) async {
|
) async {
|
||||||
if (assets.isEmpty) return ([].cast<Asset>(), [].cast<Asset>());
|
if (assets.isEmpty) return ([].cast<Asset>(), [].cast<Asset>());
|
||||||
|
|
||||||
final List<Asset?> inDb = await _db.assets.getAllByChecksumOwnerId(
|
final List<Asset?> inDb = await _db.assets.getAllByOwnerIdChecksum(
|
||||||
assets.map((a) => a.checksum).toList(growable: false),
|
|
||||||
assets.map((a) => a.ownerId).toInt64List(),
|
assets.map((a) => a.ownerId).toInt64List(),
|
||||||
|
assets.map((a) => a.checksum).toList(growable: false),
|
||||||
);
|
);
|
||||||
assert(inDb.length == assets.length);
|
assert(inDb.length == assets.length);
|
||||||
final List<Asset> existing = [], toUpsert = [];
|
final List<Asset> existing = [], toUpsert = [];
|
||||||
|
@ -683,9 +683,9 @@ class SyncService {
|
||||||
);
|
);
|
||||||
// give details on the errors
|
// give details on the errors
|
||||||
assets.sort(Asset.compareByOwnerChecksum);
|
assets.sort(Asset.compareByOwnerChecksum);
|
||||||
final inDb = await _db.assets.getAllByChecksumOwnerId(
|
final inDb = await _db.assets.getAllByOwnerIdChecksum(
|
||||||
assets.map((e) => e.checksum).toList(growable: false),
|
|
||||||
assets.map((e) => e.ownerId).toInt64List(),
|
assets.map((e) => e.ownerId).toInt64List(),
|
||||||
|
assets.map((e) => e.checksum).toList(growable: false),
|
||||||
);
|
);
|
||||||
for (int i = 0; i < assets.length; i++) {
|
for (int i = 0; i < assets.length; i++) {
|
||||||
final Asset a = assets[i];
|
final Asset a = assets[i];
|
||||||
|
|
Loading…
Reference in a new issue