Default discovered-contact eviction on and harden the auto-add dialog
- Default evictDiscoveredContactsEnabled to true so the 500-entry cap stays in effect unless the user opts out - Evict until under the cap when adding, so an oversized list recovers - Pass the cap into the localized subtitle instead of hard-coding 500 - Fix German title and subtitle wording - Save: block double taps, send radio config first, show an error if persisting the setting fails - Restore untranslated.json to match dev
This commit is contained in:
1 parent
956c779e2c
commit
ef53b8f390
26 files changed
+130
-223
No files matched your search
@@ -180,7 +180,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
// continuously from the whole mesh, so without a bound this list grows for
|
||||
// as long as the app stays connected. When full, the stalest node (oldest
|
||||
// lastSeen) is evicted to make room for a newly heard one.
|
||||
static const int _maxDiscoveredContacts = 500;
|
||||
static const int maxDiscoveredContacts = 500;
|
||||
|
||||
MeshCoreConnectionState _state = MeshCoreConnectionState.disconnected;
|
||||
BluetoothDevice? _device;
|
||||
@@ -1356,9 +1356,10 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
|
||||
Future<void> _loadDiscoveredContactCache() async {
|
||||
final cached = await _discoveryContactStore.loadContacts();
|
||||
// Trim a previously-saved oversized list down to the freshest entries so a
|
||||
// device that grew unbounded before the cap existed recovers on load.
|
||||
if (_appSettingsService?.settings.evictDiscoveredContactsEnabled == true &&
|
||||
// When eviction is enabled, trim a previously-saved oversized list down to
|
||||
// the freshest entries so a device that grew unbounded before the cap
|
||||
// existed recovers on load.
|
||||
if (_evictDiscoveredContactsEnabled &&
|
||||
_trimDiscoveredContactsToLimit(cached)) {
|
||||
unawaited(_discoveryContactStore.saveContacts(cached));
|
||||
}
|
||||
@@ -1367,10 +1368,13 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
..addAll(cached);
|
||||
}
|
||||
|
||||
bool get _evictDiscoveredContactsEnabled =>
|
||||
_appSettingsService?.settings.evictDiscoveredContactsEnabled ?? true;
|
||||
|
||||
bool _trimDiscoveredContactsToLimit(List<Contact> contacts) {
|
||||
if (contacts.length <= _maxDiscoveredContacts) return false;
|
||||
if (contacts.length <= maxDiscoveredContacts) return false;
|
||||
contacts.sort((a, b) => b.lastSeen.compareTo(a.lastSeen));
|
||||
contacts.removeRange(_maxDiscoveredContacts, contacts.length);
|
||||
contacts.removeRange(maxDiscoveredContacts, contacts.length);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -8194,9 +8198,10 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
flags: 0,
|
||||
);
|
||||
|
||||
if (_appSettingsService?.settings.evictDiscoveredContactsEnabled == true &&
|
||||
_discoveredContacts.length >= _maxDiscoveredContacts) {
|
||||
_evictStalestDiscoveredContact();
|
||||
if (_evictDiscoveredContactsEnabled) {
|
||||
while (_discoveredContacts.length >= maxDiscoveredContacts) {
|
||||
_evictStalestDiscoveredContact();
|
||||
}
|
||||
}
|
||||
_discoveredContacts.add(disContact);
|
||||
|
||||
|
||||
Reference in new issue
Block a user