1
0
mirror of https://github.com/immich-app/immich.git synced 2024-11-28 09:33:27 +02:00

fix(mobile): unnecessary rebuilds from partner share notifier (#14170)

* fix unnecessary notifications

* move equality function

* sort by id

* use same comparison for initial and later queries
This commit is contained in:
Mert 2024-11-17 12:04:55 -05:00 committed by GitHub
parent 4b5657c21e
commit 944ea7dbcd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,6 @@
import 'dart:async'; import 'dart:async';
import 'package:collection/collection.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/providers/album/suggested_shared_users.provider.dart'; import 'package:immich_mobile/providers/album/suggested_shared_users.provider.dart';
import 'package:immich_mobile/services/partner.service.dart'; import 'package:immich_mobile/services/partner.service.dart';
@ -9,9 +10,19 @@ import 'package:isar/isar.dart';
class PartnerSharedWithNotifier extends StateNotifier<List<User>> { class PartnerSharedWithNotifier extends StateNotifier<List<User>> {
PartnerSharedWithNotifier(Isar db, this._ps) : super([]) { PartnerSharedWithNotifier(Isar db, this._ps) : super([]) {
final query = db.users.filter().isPartnerSharedWithEqualTo(true); Function eq = const ListEquality<User>().equals;
query.findAll().then((partners) => state = partners); final query = db.users.filter().isPartnerSharedWithEqualTo(true).sortById();
query.watch().listen((partners) => state = partners); query.findAll().then((partners) {
if (!eq(state, partners)) {
state = partners;
}
}).then((_) {
query.watch().listen((partners) {
if (!eq(state, partners)) {
state = partners;
}
});
});
} }
Future<bool> updatePartner(User partner, {required bool inTimeline}) { Future<bool> updatePartner(User partner, {required bool inTimeline}) {
@ -31,9 +42,19 @@ final partnerSharedWithProvider =
class PartnerSharedByNotifier extends StateNotifier<List<User>> { class PartnerSharedByNotifier extends StateNotifier<List<User>> {
PartnerSharedByNotifier(Isar db) : super([]) { PartnerSharedByNotifier(Isar db) : super([]) {
final query = db.users.filter().isPartnerSharedByEqualTo(true); Function eq = const ListEquality<User>().equals;
query.findAll().then((partners) => state = partners); final query = db.users.filter().isPartnerSharedByEqualTo(true).sortById();
streamSub = query.watch().listen((partners) => state = partners); query.findAll().then((partners) {
if (!eq(state, partners)) {
state = partners;
}
}).then((_) {
streamSub = query.watch().listen((partners) {
if (!eq(state, partners)) {
state = partners;
}
});
});
} }
late final StreamSubscription<List<User>> streamSub; late final StreamSubscription<List<User>> streamSub;