Skip to content

Commit 500ae49

Browse files
authored
fix: loadCachedDb() before backfill to ensure in-mem nodedb isn't stale, show filtered count in nodelist (#3827)
1 parent 4cecc57 commit 500ae49

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

app/src/main/java/com/geeksville/mesh/service/MeshService.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ class MeshService : Service() {
410410
}
411411
.launchIn(serviceScope)
412412

413-
loadSettings() // Load our last known node DB
413+
loadCachedNodeDB() // Load our last known node DB
414414

415415
// the rest of our init will happen once we are in radioConnection.onServiceConnected
416416
}
@@ -482,7 +482,7 @@ class MeshService : Service() {
482482
// BEGINNING OF MODEL - FIXME, move elsewhere
483483
//
484484

485-
private fun loadSettings() = serviceScope.handledLaunch {
485+
private fun loadCachedNodeDB() = serviceScope.handledLaunch {
486486
myNodeInfo = nodeRepository.myNodeInfo.value
487487
nodeDBbyNodeNum.putAll(nodeRepository.getNodeDBbyNum().first())
488488
// Note: we do not haveNodeDB = true because that means we've got a valid db from a real
@@ -2104,7 +2104,9 @@ class MeshService : Service() {
21042104
} else {
21052105
newNodes.forEach(::installNodeInfo)
21062106
newNodes.clear()
2107-
serviceScope.handledLaunch { nodeRepository.installConfig(myNodeInfo!!, nodeDBbyNodeNum.values.toList()) }
2107+
// Individual nodes are already upserted to DB via updateNodeInfo->nodeRepository.upsert
2108+
// Only call installConfig to persist myNodeInfo, not to overwrite all nodes
2109+
serviceScope.handledLaunch { myNodeInfo?.let { nodeRepository.installConfig(it, emptyList()) } }
21082110
haveNodeDB = true
21092111
flushEarlyReceivedPackets("node_info_complete")
21102112
sendAnalytics()
@@ -2310,6 +2312,8 @@ class MeshService : Service() {
23102312
historyLog { dbSummary }
23112313
// Do not clear packet DB here; messages are per-device and should persist
23122314
clearNotifications()
2315+
// Reload nodes from the newly switched database
2316+
loadCachedNodeDB()
23132317
}
23142318
} else {
23152319
Timber.d("SetDeviceAddress: Device address is unchanged, ignoring.")

core/strings/src/commonMain/composeResources/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@
774774
<string name="modules_unlocked">Modules unlocked</string>
775775
<string name="modules_already_unlocked">Modules already unlocked</string>
776776
<string name="remote">Remote</string>
777-
<string name="node_count_template">(%1$d online / %2$d total)</string>
777+
<string name="node_count_template">(%1$d online / %2$d shown / %3$d total)</string>
778778
<string name="react">React</string>
779779
<string name="disconnect">Disconnect</string>
780780
<string name="scanning_bluetooth">Scanning for Bluetooth devices…</string>

feature/messaging/src/main/kotlin/org/meshtastic/feature/messaging/MessageListPaged.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ private fun UpdateUnreadCountPaged(
367367
}
368368
.debounce(timeoutMillis = UnreadUiDefaults.SCROLL_DEBOUNCE_MILLIS)
369369
.collectLatest { index ->
370+
// Only mark messages as read if we have a valid index (screen is visible and not scrolling)
370371
if (index != null) {
371372
val lastUnreadIndex = findLastUnreadMessageIndex(messages)
372373
// If we're at/past the oldest unread, mark the first visible unread message

feature/node/src/main/kotlin/org/meshtastic/feature/node/list/NodeListScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ fun NodeListScreen(
122122
topBar = {
123123
MainAppBar(
124124
title = stringResource(Res.string.nodes),
125-
subtitle = stringResource(Res.string.node_count_template, onlineNodeCount, totalNodeCount),
125+
subtitle = stringResource(Res.string.node_count_template, onlineNodeCount, nodes.size, totalNodeCount),
126126
ourNode = ourNode,
127127
showNodeChip = false,
128128
canNavigateUp = false,

0 commit comments

Comments
 (0)