diff --git a/mobile/lib/modules/map/services/map.service.dart b/mobile/lib/modules/map/services/map.service.dart index 8b4e8064c4..b5ee010014 100644 --- a/mobile/lib/modules/map/services/map.service.dart +++ b/mobile/lib/modules/map/services/map.service.dart @@ -48,10 +48,8 @@ class MapSerivce { if (assets.isNotEmpty) return assets[0]; final dto = await _apiService.assetApi.getAssetById(remoteId); - if (dto == null) { - return null; - } - return Asset.remote(dto); + if (dto == null) return null; + return _db.assets.getByRemoteId(dto.id); } catch (error, stack) { _log.severe( "Cannot get asset for marker ${error.toString()}", diff --git a/mobile/lib/modules/memories/services/memory.service.dart b/mobile/lib/modules/memories/services/memory.service.dart index 338c79e553..8d2cd226a4 100644 --- a/mobile/lib/modules/memories/services/memory.service.dart +++ b/mobile/lib/modules/memories/services/memory.service.dart @@ -2,13 +2,16 @@ import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:immich_mobile/shared/models/asset.dart'; import 'package:immich_mobile/modules/memories/models/memory.dart'; import 'package:immich_mobile/shared/providers/api.provider.dart'; +import 'package:immich_mobile/shared/providers/db.provider.dart'; import 'package:immich_mobile/shared/services/api.service.dart'; +import 'package:isar/isar.dart'; import 'package:logging/logging.dart'; import 'package:openapi/api.dart'; final memoryServiceProvider = StateProvider((ref) { return MemoryService( ref.watch(apiServiceProvider), + ref.watch(dbProvider), ); }); @@ -16,8 +19,9 @@ class MemoryService { final log = Logger("MemoryService"); final ApiService _apiService; + final Isar _db; - MemoryService(this._apiService); + MemoryService(this._apiService, this._db); Future?> getMemoryLane() async { try { @@ -36,7 +40,7 @@ class MemoryService { memories.add( Memory( title: title, - assets: assets.map((a) => Asset.remote(a)).toList(), + assets: await _db.assets.getAllByRemoteId(assets.map((e) => e.id)), ), ); } diff --git a/mobile/lib/modules/search/providers/all_video_assets.provider.dart b/mobile/lib/modules/search/providers/all_video_assets.provider.dart index eb46ad2596..e2c7edec97 100644 --- a/mobile/lib/modules/search/providers/all_video_assets.provider.dart +++ b/mobile/lib/modules/search/providers/all_video_assets.provider.dart @@ -1,28 +1,13 @@ import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:immich_mobile/shared/models/asset.dart'; -import 'package:immich_mobile/shared/providers/api.provider.dart'; import 'package:immich_mobile/shared/providers/db.provider.dart'; +import 'package:isar/isar.dart'; -final allVideoAssetsProvider = FutureProvider>( (ref) async { - final search = await ref.watch(apiServiceProvider).searchApi.search( - type: 'VIDEO', - ); - - if (search == null) { - return []; - } - - return ref.watch(dbProvider) +final allVideoAssetsProvider = FutureProvider>((ref) async { + return ref + .watch(dbProvider) .assets - .getAllByRemoteId( - search.assets.items.map((e) => e.id), - ); - - /// This works offline, but we use the above - /* - return ref.watch(dbProvider).assets .filter() - .durationInSecondsGreaterThan(0) + .typeEqualTo(AssetType.video) .findAll(); - */ }); diff --git a/mobile/lib/modules/search/services/person.service.dart b/mobile/lib/modules/search/services/person.service.dart index d4cbe0de5b..4f92e729f5 100644 --- a/mobile/lib/modules/search/services/person.service.dart +++ b/mobile/lib/modules/search/services/person.service.dart @@ -1,6 +1,8 @@ import 'package:immich_mobile/shared/models/asset.dart'; import 'package:immich_mobile/shared/providers/api.provider.dart'; +import 'package:immich_mobile/shared/providers/db.provider.dart'; import 'package:immich_mobile/shared/services/api.service.dart'; +import 'package:isar/isar.dart'; import 'package:logging/logging.dart'; import 'package:openapi/api.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; @@ -9,13 +11,14 @@ part 'person.service.g.dart'; @riverpod PersonService personService(PersonServiceRef ref) => - PersonService(ref.read(apiServiceProvider)); + PersonService(ref.read(apiServiceProvider), ref.read(dbProvider)); class PersonService { final Logger _log = Logger("PersonService"); final ApiService _apiService; + final Isar _db; - PersonService(this._apiService); + PersonService(this._apiService, this._db); Future> getCuratedPeople() async { try { @@ -30,7 +33,8 @@ class PersonService { Future?> getPersonAssets(String id) async { try { final assets = await _apiService.personApi.getPersonAssets(id); - return assets?.map((e) => Asset.remote(e)).toList(); + if (assets == null) return null; + return await _db.assets.getAllByRemoteId(assets.map((e) => e.id)); } catch (error, stack) { _log.severe("Error while fetching person assets", error, stack); } diff --git a/mobile/lib/shared/models/asset.dart b/mobile/lib/shared/models/asset.dart index 68234dab4b..8fa90c7806 100644 --- a/mobile/lib/shared/models/asset.dart +++ b/mobile/lib/shared/models/asset.dart @@ -472,6 +472,8 @@ extension AssetsHelper on IsarCollection { ids.isEmpty ? Future.value([]) : remote(ids).findAll(); Future> getAllByLocalId(Iterable ids) => ids.isEmpty ? Future.value([]) : local(ids).findAll(); + Future getByRemoteId(String id) => + where().remoteIdEqualTo(id).findFirst(); QueryBuilder remote(Iterable ids) => where().anyOf(ids, (q, String e) => q.remoteIdEqualTo(e));