mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-08-11 16:30:28 +00:00
feat: Implement optimized contact fetching by public key to enhance performance
This commit is contained in:
@@ -236,11 +236,12 @@ class AppProvider with ChangeNotifier {
|
||||
// When a contact's routing path is updated in the mesh network
|
||||
connectionProvider.onPathUpdated = (publicKey) {
|
||||
debugPrint('🔄 [AppProvider] Path updated for contact: ${publicKey.sublist(0, 6).map((b) => b.toRadixString(16).padLeft(2, '0')).join(':')}...');
|
||||
// Trigger a contact sync to get the updated path information
|
||||
// Trigger a single contact fetch to get the updated path information
|
||||
// This is much more efficient than fetching all contacts
|
||||
// This happens asynchronously to avoid blocking the event handler
|
||||
Future.delayed(const Duration(milliseconds: 100), () {
|
||||
if (connectionProvider.deviceInfo.isConnected) {
|
||||
connectionProvider.getContacts();
|
||||
connectionProvider.getContact(publicKey);
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -252,11 +253,12 @@ class AppProvider with ChangeNotifier {
|
||||
// Check if this is an existing contact that might have updated location
|
||||
final contact = contactsProvider.findContactByKey(publicKey);
|
||||
if (contact != null) {
|
||||
debugPrint(' Existing contact "${contact.advName}" - triggering contact sync for updates');
|
||||
// Trigger a contact sync to get the updated contact information
|
||||
debugPrint(' Existing contact "${contact.advName}" - fetching updated contact info (optimized)');
|
||||
// Trigger a single contact fetch to get the updated contact information
|
||||
// This is much more efficient than fetching all contacts
|
||||
Future.delayed(const Duration(milliseconds: 100), () {
|
||||
if (connectionProvider.deviceInfo.isConnected) {
|
||||
connectionProvider.getContacts();
|
||||
connectionProvider.getContact(publicKey);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -686,6 +686,30 @@ class ConnectionProvider with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get a single contact by public key from device
|
||||
///
|
||||
/// This is more efficient than getContacts() when you only need to refresh
|
||||
/// one specific contact (e.g., after receiving an advertisement or path update).
|
||||
///
|
||||
/// The contact will be delivered via the onContactReceived callback.
|
||||
Future<void> getContact(Uint8List publicKey) async {
|
||||
if (!_bleService.isConnected) {
|
||||
_error = 'Not connected to device';
|
||||
notifyListeners();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await _bleService.getContactByKey(publicKey);
|
||||
} catch (e) {
|
||||
_error = 'Failed to get contact: $e';
|
||||
debugPrint('⚠️ [Provider] Failed to get contact by key, falling back to full contact sync');
|
||||
// Fallback to full contact sync if command not supported
|
||||
await _bleService.getContacts();
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
/// Sync all channels from device
|
||||
Future<void> syncChannels({int? maxChannels}) async {
|
||||
if (!_bleService.isConnected) {
|
||||
|
||||
Reference in New Issue
Block a user