kopia lustrzana https://gitlab.com/mysocialportal/relatica
Fix connections background update making too many fast calls.
rodzic
5e2efeceff
commit
cfa1ad79ca
|
@ -94,7 +94,7 @@ class _ContactsScreenState extends State<ContactsScreen> {
|
||||||
if (nss.connectionUpdateStatus.value) {
|
if (nss.connectionUpdateStatus.value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
manager.updateAllContacts();
|
manager.updateAllContacts(false);
|
||||||
return;
|
return;
|
||||||
},
|
},
|
||||||
child: Column(
|
child: Column(
|
||||||
|
@ -129,7 +129,8 @@ class _ContactsScreenState extends State<ContactsScreen> {
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: StatusAndRefreshButton(
|
child: StatusAndRefreshButton(
|
||||||
valueListenable: nss.connectionUpdateStatus,
|
valueListenable: nss.connectionUpdateStatus,
|
||||||
refreshFunction: () async => manager.updateAllContacts(),
|
refreshFunction: () async =>
|
||||||
|
manager.updateAllContacts(false),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
|
|
@ -154,7 +154,7 @@ class ConnectionsManager extends ChangeNotifier {
|
||||||
return conRepo.getMyContacts();
|
return conRepo.getMyContacts();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> updateAllContacts() async {
|
Future<void> updateAllContacts(bool backgroundUpdate) async {
|
||||||
_logger.fine('Updating all contacts');
|
_logger.fine('Updating all contacts');
|
||||||
_lastUpdateStatus = 'Updating';
|
_lastUpdateStatus = 'Updating';
|
||||||
final persistentInfo = getIt<ActiveProfileSelector<PersistentInfoService>>()
|
final persistentInfo = getIt<ActiveProfileSelector<PersistentInfoService>>()
|
||||||
|
@ -163,6 +163,9 @@ class ConnectionsManager extends ChangeNotifier {
|
||||||
final originalTime = persistentInfo.lastMyConnectionsUpdate;
|
final originalTime = persistentInfo.lastMyConnectionsUpdate;
|
||||||
await persistentInfo.updateLastMyConnectionUpdate(DateTime.now());
|
await persistentInfo.updateLastMyConnectionUpdate(DateTime.now());
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
final delay = backgroundUpdate
|
||||||
|
? const Duration(minutes: 5)
|
||||||
|
: const Duration(seconds: 10);
|
||||||
try {
|
try {
|
||||||
final client = RelationshipsClient(profile);
|
final client = RelationshipsClient(profile);
|
||||||
final results = <String, Connection>{};
|
final results = <String, Connection>{};
|
||||||
|
@ -186,7 +189,7 @@ class ConnectionsManager extends ChangeNotifier {
|
||||||
}, onError: (error) {
|
}, onError: (error) {
|
||||||
_logger.severe('Error getting followers data: $error');
|
_logger.severe('Error getting followers data: $error');
|
||||||
});
|
});
|
||||||
await Future.delayed(Duration.zero);
|
await Future.delayed(delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
moreResults = true;
|
moreResults = true;
|
||||||
|
@ -210,7 +213,7 @@ class ConnectionsManager extends ChangeNotifier {
|
||||||
}, onError: (error) {
|
}, onError: (error) {
|
||||||
_logger.severe('Error getting followers data: $error');
|
_logger.severe('Error getting followers data: $error');
|
||||||
});
|
});
|
||||||
await Future.delayed(Duration.zero);
|
await Future.delayed(delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final noLongerFollowed in originalContacts) {
|
for (final noLongerFollowed in originalContacts) {
|
||||||
|
|
|
@ -41,7 +41,7 @@ Future<void> executeUpdatesForProfile(Profile profile) async {
|
||||||
if (dt >= _connectionsRefreshInterval) {
|
if (dt >= _connectionsRefreshInterval) {
|
||||||
await getIt<ActiveProfileSelector<ConnectionsManager>>()
|
await getIt<ActiveProfileSelector<ConnectionsManager>>()
|
||||||
.getForProfile(profile)
|
.getForProfile(profile)
|
||||||
.withResultAsync((m) async => await m.updateAllContacts())
|
.withResultAsync((m) async => await m.updateAllContacts(true))
|
||||||
.withError((error) {
|
.withError((error) {
|
||||||
_logger.severe('Error running connections update: $error');
|
_logger.severe('Error running connections update: $error');
|
||||||
});
|
});
|
||||||
|
|
Ładowanie…
Reference in New Issue