Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Nov 17, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions mobile/lib/providers/partner.provider.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';

import 'package:collection/collection.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/providers/album/suggested_shared_users.provider.dart';
import 'package:immich_mobile/services/partner.service.dart';
Expand All @@ -9,9 +10,19 @@ import 'package:isar/isar.dart';

class PartnerSharedWithNotifier extends StateNotifier<List<User>> {
PartnerSharedWithNotifier(Isar db, this._ps) : super([]) {
final query = db.users.filter().isPartnerSharedWithEqualTo(true);
query.findAll().then((partners) => state = partners);
query.watch().listen((partners) => state = partners);
final query = db.users.filter().isPartnerSharedWithEqualTo(true).sortById();
query.findAll().then((partners) {
if (partners.isNotEmpty) {
mertalev marked this conversation as resolved.
Show resolved Hide resolved
state = partners;
}
}).then((_) {
Function eq = const ListEquality<User>().equals;
query.watch().listen((partners) {
if (!eq(state, partners)) {
state = partners;
}
});
});
}

Future<bool> updatePartner(User partner, {required bool inTimeline}) {
Expand All @@ -31,9 +42,19 @@ final partnerSharedWithProvider =

class PartnerSharedByNotifier extends StateNotifier<List<User>> {
PartnerSharedByNotifier(Isar db) : super([]) {
final query = db.users.filter().isPartnerSharedByEqualTo(true);
query.findAll().then((partners) => state = partners);
streamSub = query.watch().listen((partners) => state = partners);
final query = db.users.filter().isPartnerSharedByEqualTo(true).sortById();
query.findAll().then((partners) {
if (partners.isNotEmpty) {
mertalev marked this conversation as resolved.
Show resolved Hide resolved
state = partners;
}
}).then((_) {
Function eq = const ListEquality<User>().equals;
streamSub = query.watch().listen((partners) {
if (!eq(state, partners)) {
state = partners;
}
});
});
}

late final StreamSubscription<List<User>> streamSub;
Expand Down
Loading