From 098ab9eae5ef4d60fd23fe97afdb7475ee12d6a8 Mon Sep 17 00:00:00 2001 From: Fynn Petersen-Frey <10599762+fyfrey@users.noreply.github.com> Date: Thu, 28 Sep 2023 05:43:55 +0200 Subject: [PATCH] fix(mobile): speed up RenderList creation for timeline (#4103) Co-authored-by: Alex --- .../providers/archive_asset_provider.dart | 3 ++- .../favorite/providers/favorite_provider.dart | 3 ++- .../asset_grid/asset_grid_data_structure.dart | 2 +- mobile/lib/shared/models/asset.dart | 11 +++++------ mobile/lib/shared/models/asset.g.dart | Bin 72553 -> 72400 bytes .../lib/shared/providers/asset.provider.dart | 3 ++- mobile/lib/shared/services/sync.service.dart | 14 +++++++------- 7 files changed, 19 insertions(+), 17 deletions(-) diff --git a/mobile/lib/modules/archive/providers/archive_asset_provider.dart b/mobile/lib/modules/archive/providers/archive_asset_provider.dart index 26d0b2eea9..1f151b9228 100644 --- a/mobile/lib/modules/archive/providers/archive_asset_provider.dart +++ b/mobile/lib/modules/archive/providers/archive_asset_provider.dart @@ -13,8 +13,9 @@ final archiveProvider = StreamProvider((ref) async* { final query = ref .watch(dbProvider) .assets + .where() + .ownerIdEqualToAnyChecksum(user.isarId) .filter() - .ownerIdEqualTo(user.isarId) .isArchivedEqualTo(true) .sortByFileCreatedAt(); final settings = ref.watch(appSettingsServiceProvider); diff --git a/mobile/lib/modules/favorite/providers/favorite_provider.dart b/mobile/lib/modules/favorite/providers/favorite_provider.dart index 4ddb73ea69..2439d627fa 100644 --- a/mobile/lib/modules/favorite/providers/favorite_provider.dart +++ b/mobile/lib/modules/favorite/providers/favorite_provider.dart @@ -13,8 +13,9 @@ final favoriteAssetsProvider = StreamProvider((ref) async* { final query = ref .watch(dbProvider) .assets + .where() + .ownerIdEqualToAnyChecksum(user.isarId) .filter() - .ownerIdEqualTo(user.isarId) .isFavoriteEqualTo(true) .sortByFileCreatedAt(); final settings = ref.watch(appSettingsServiceProvider); diff --git a/mobile/lib/modules/home/ui/asset_grid/asset_grid_data_structure.dart b/mobile/lib/modules/home/ui/asset_grid/asset_grid_data_structure.dart index d5a0c0d928..9e5f77caf6 100644 --- a/mobile/lib/modules/home/ui/asset_grid/asset_grid_data_structure.dart +++ b/mobile/lib/modules/home/ui/asset_grid/asset_grid_data_structure.dart @@ -142,7 +142,7 @@ class RenderList { ) async { final List elements = []; - const pageSize = 500; + const pageSize = 50000; const sectionSize = 60; // divides evenly by 2,3,4,5,6 if (groupBy == GroupAssetsBy.none) { diff --git a/mobile/lib/shared/models/asset.dart b/mobile/lib/shared/models/asset.dart index e8f969a111..cea12e7b62 100644 --- a/mobile/lib/shared/models/asset.dart +++ b/mobile/lib/shared/models/asset.dart @@ -100,12 +100,6 @@ class Asset { /// stores the raw SHA1 bytes as a base64 String /// because Isar cannot sort lists of byte arrays - @Index( - unique: true, - replace: false, - type: IndexType.hash, - composite: [CompositeIndex("ownerId")], - ) String checksum; @Index(unique: false, replace: false, type: IndexType.hash) @@ -114,6 +108,11 @@ class Asset { @Index(unique: false, replace: false, type: IndexType.hash) String? localId; + @Index( + unique: true, + replace: false, + composite: [CompositeIndex("checksum", type: IndexType.hash)], + ) int ownerId; DateTime fileCreatedAt; diff --git a/mobile/lib/shared/models/asset.g.dart b/mobile/lib/shared/models/asset.g.dart index 713c26885b95a41168d52c4c1b8ca7d3433b6f37..606f9692e99c7cd22577f125b690687ed4e92de6 100644 GIT binary patch delta 1974 zcmcIlOH30{6pe<2>6hVGp{?|lwzks@QCdDlY@jWmd=yQKiB5v|g!HwCfN|X%4C`ai zpl^nEx@ckBxW!tBa{|uvPei0@o@qfu>AiP6G_~5mj0|_A7yF!U9>pmLQ6ZyTrxu}m zTJjUhX0h0XCb1Y^lo3Q1g`^sZmftZC56W9f1r4xK!%hrdN&Dpt zPKY=Yn@R|ZD5UKN^S(M*5k?;S4I~pgSb7cA`Jo-S7aqB_sdNr!E}}RX!}YKkEQjlv za#-rFA|5pG`D%#nv>}|${v&NQZ3W%3ZnD;g2QBb3#1OhUx)Q=z%wc@Q5ah$(OH%zl z5&>(^63vGWhtyzcGa=cB;RK)wv?hg`k|dVRmPU`(I9PM(TdPO!$NET+X)c+rwt*IC@bSP zk-KoAF(Gkd)TE*4nz(XfG;!s|z|sX86Sty6J8#gwsdOQ;Xr^z@JLlYU@0~Wu0!e)79O{-@4mbwi`ANHP)6O{wO?Cq~M8i z6yi!2^vV#p6uQDTHE?jXenW+P0^#rupFe6F&1Pm3(+KM@u<0{^0Vyna1=Cs?G>+F8 zRJ6luT|_!_8Rh6gB2tN#f|p2ECG{tSs&l*Es)*V$R&4H{hQst(3ZX@c|GAP(#!!@t zaaqp0P<0LKt(vy#lwgzAg38#SE#tQF+WZA+Yx4mHwoHv+G;3hRcnkt&1*}*#5Hmk+ z!Wv^!u^cxyJ{#W6{GP1^?wC|648aA%bCa#9Osv?9|0Ae?A&ZO@M;fCRpwy#!Egcap#{yM+MWwqGKEg&+2Bwc^b!ScS0M;^pVz_lkW3sP1|Is?#D5cTc}@RU zs7nDo _syncNewAssetToDb(Asset a) async { final Asset? inDb = - await _db.assets.getByChecksumOwnerId(a.checksum, a.ownerId); + await _db.assets.getByOwnerIdChecksum(a.ownerId, a.checksum); if (inDb != null) { // unify local/remote assets by replacing the // local-only asset in the DB with a local&remote asset @@ -195,8 +195,8 @@ class SyncService { return false; } final List inDb = await _db.assets - .filter() - .ownerIdEqualTo(user.isarId) + .where() + .ownerIdEqualToAnyChecksum(user.isarId) .sortByChecksum() .findAll(); assert(inDb.isSorted(Asset.compareByChecksum), "inDb not sorted!"); @@ -638,9 +638,9 @@ class SyncService { ) async { if (assets.isEmpty) return ([].cast(), [].cast()); - final List inDb = await _db.assets.getAllByChecksumOwnerId( - assets.map((a) => a.checksum).toList(growable: false), + final List inDb = await _db.assets.getAllByOwnerIdChecksum( assets.map((a) => a.ownerId).toInt64List(), + assets.map((a) => a.checksum).toList(growable: false), ); assert(inDb.length == assets.length); final List existing = [], toUpsert = []; @@ -683,9 +683,9 @@ class SyncService { ); // give details on the errors assets.sort(Asset.compareByOwnerChecksum); - final inDb = await _db.assets.getAllByChecksumOwnerId( - assets.map((e) => e.checksum).toList(growable: false), + final inDb = await _db.assets.getAllByOwnerIdChecksum( assets.map((e) => e.ownerId).toInt64List(), + assets.map((e) => e.checksum).toList(growable: false), ); for (int i = 0; i < assets.length; i++) { final Asset a = assets[i];