refactor(MeshService): remove `discardNodeDB` and simplify logic

pull/1244/head
andrekir 2024-09-13 18:38:04 -03:00
rodzic 1252b67fce
commit a98d3899e6
3 zmienionych plików z 3 dodań i 17 usunięć

Wyświetl plik

@ -70,14 +70,10 @@ class NodeDB @Inject constructor(
nodeInfoDao.upsert(node)
}
suspend fun clearNodeDB() = withContext(Dispatchers.IO) {
nodeInfoDao.clearNodeInfo()
nodeInfoDao.clearMyNodeInfo()
}
suspend fun installNodeDB(mi: MyNodeInfo, nodes: List<NodeInfo>) = withContext(Dispatchers.IO) {
clearNodeDB()
nodeInfoDao.clearMyNodeInfo()
nodeInfoDao.setMyNodeInfo(mi) // set MyNodeInfo first
nodeInfoDao.clearNodeInfo()
nodeInfoDao.putAll(nodes)
}

Wyświetl plik

@ -57,7 +57,6 @@ class RadioConfigRepository @Inject constructor(
val nodeDBbyNum: StateFlow<Map<Int, NodeInfo>> get() = nodeDB.nodeDBbyNum
suspend fun upsert(node: NodeInfo) = nodeDB.upsert(node)
suspend fun clearNodeDB() = nodeDB.clearNodeDB()
suspend fun installNodeDB(mi: MyNodeInfo, nodes: List<NodeInfo>) {
nodeDB.installNodeDB(mi, nodes)
}

Wyświetl plik

@ -323,15 +323,6 @@ class MeshService : Service(), Logging {
/// BEGINNING OF MODEL - FIXME, move elsewhere
///
/**
* discard entire node db - used before downloading a new db from the device
*/
private fun discardNodeDB() = serviceScope.handledLaunch {
debug("Discarding NodeDB")
radioConfigRepository.clearNodeDB()
haveNodeDB = false
}
val myNodeInfo: MyNodeInfo? get() = radioConfigRepository.myNodeInfo.value
private val configTotal by lazy { ConfigProtos.Config.getDescriptor().fields.size }
@ -1591,7 +1582,7 @@ class MeshService : Service(), Logging {
val res = radioInterfaceService.setDeviceAddress(deviceAddr)
if (res) {
discardNodeDB()
haveNodeDB = false
} else {
serviceBroadcasts.broadcastConnection()
}