refactor: reactive driftGetAllPeopleProvider (#30660)

Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
This commit is contained in:
shenlong 2026-08-12 21:12:12 +05:30 committed by GitHub
parent 52edcc0c74
commit 303a9f15b1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 10 additions and 22 deletions

View file

@ -18,8 +18,8 @@ class DriftPeopleService {
return _repository.getAssetPeople(assetId);
}
Future<List<Person>> getAllPeople({int minFaces = 3}) {
return _repository.getAllPeople(minFaces: minFaces);
Stream<List<Person>> watch({int minFaces = 3}) {
return _repository.watch(minFaces: minFaces);
}
Future<int> updateName(String personId, String name) async {
@ -27,7 +27,7 @@ class DriftPeopleService {
return _repository.updateName(personId, name);
}
Future<int> updateBrithday(String personId, DateTime birthday) async {
Future<int> updateBirthday(String personId, DateTime birthday) async {
await _personApiRepository.update(personId, birthday: birthday);
return _repository.updateBirthday(personId, birthday);
}

View file

@ -33,7 +33,7 @@ class DriftPeopleRepository extends DriftDatabaseRepository {
return query.map((row) => row.toDto()).get();
}
Future<List<Person>> getAllPeople({int minFaces = 3}) async {
Stream<List<Person>> watch({int minFaces = 3}) {
final people = _db.personEntity;
final faces = _db.assetFaceEntity;
final assets = _db.remoteAssetEntity;
@ -59,7 +59,7 @@ class DriftPeopleRepository extends DriftDatabaseRepository {
return query.map((row) {
final person = row.readTable(people);
return person.toDto();
}).get();
}).watch();
}
Future<int> updateName(String personId, String name) {

View file

@ -12,7 +12,6 @@ import 'package:immich_mobile/presentation/pages/search/paginated_search.provide
import 'package:immich_mobile/providers/haptic_feedback.provider.dart';
import 'package:immich_mobile/providers/infrastructure/album.provider.dart';
import 'package:immich_mobile/providers/infrastructure/memory.provider.dart';
import 'package:immich_mobile/providers/infrastructure/people.provider.dart';
import 'package:immich_mobile/providers/infrastructure/readonly_mode.provider.dart';
import 'package:immich_mobile/providers/search/search_input_focus.provider.dart';
import 'package:immich_mobile/providers/tab.provider.dart';
@ -132,7 +131,6 @@ void _onNavigationSelected(TabsRouter router, int index, WidgetRef ref) {
// Library page
if (index == kLibraryTabIndex) {
ref.invalidate(localAlbumProvider);
ref.invalidate(driftGetAllPeopleProvider);
}
ref.read(hapticFeedbackProvider.notifier).selectionClick();

View file

@ -30,14 +30,9 @@ class _DriftPersonNameEditFormState extends ConsumerState<DriftPersonBirthdayEdi
Future<void> saveBirthday() async {
try {
final result = await ref.read(driftPeopleServiceProvider).updateBrithday(widget.person.id, _selectedDate);
if (result != 0) {
ref.invalidate(driftGetAllPeopleProvider);
if (!mounted) {
return;
}
final result = await ref.read(driftPeopleServiceProvider).updateBirthday(widget.person.id, _selectedDate);
if (result != 0 && mounted) {
context.pop<DateTime>(_selectedDate);
}
} catch (error) {

View file

@ -29,12 +29,7 @@ class _DriftPersonNameEditFormState extends ConsumerState<DriftPersonNameEditFor
Future<void> onEdit(String personId, String newName) async {
try {
final result = await ref.read(driftPeopleServiceProvider).updateName(personId, newName);
if (result != 0) {
ref.invalidate(driftGetAllPeopleProvider);
if (!mounted) {
return;
}
if (result != 0 && mounted) {
context.pop<String>(newName);
}
} catch (error) {

View file

@ -19,8 +19,8 @@ final driftPeopleAssetProvider = FutureProvider.family<List<Person>, String>((re
return service.getAssetPeople(assetId);
});
final driftGetAllPeopleProvider = FutureProvider<List<Person>>((ref) async {
final driftGetAllPeopleProvider = StreamProvider<List<Person>>((ref) async* {
final service = ref.watch(driftPeopleServiceProvider);
final prefs = await ref.watch(userMetadataPreferencesProvider.future);
return service.getAllPeople(minFaces: prefs?.minimumFaces ?? 3);
yield* service.watch(minFaces: prefs?.minimumFaces ?? 3);
});