From a98d3899e65b08fe377be6995f78654b61d5beea Mon Sep 17 00:00:00 2001 From: andrekir Date: Fri, 13 Sep 2024 18:38:04 -0300 Subject: [PATCH] refactor(MeshService): remove `discardNodeDB` and simplify logic --- app/src/main/java/com/geeksville/mesh/model/NodeDB.kt | 8 ++------ .../repository/datastore/RadioConfigRepository.kt | 1 - .../java/com/geeksville/mesh/service/MeshService.kt | 11 +---------- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/model/NodeDB.kt b/app/src/main/java/com/geeksville/mesh/model/NodeDB.kt index 5b418417..e38c720e 100644 --- a/app/src/main/java/com/geeksville/mesh/model/NodeDB.kt +++ b/app/src/main/java/com/geeksville/mesh/model/NodeDB.kt @@ -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) = withContext(Dispatchers.IO) { - clearNodeDB() + nodeInfoDao.clearMyNodeInfo() nodeInfoDao.setMyNodeInfo(mi) // set MyNodeInfo first + nodeInfoDao.clearNodeInfo() nodeInfoDao.putAll(nodes) } diff --git a/app/src/main/java/com/geeksville/mesh/repository/datastore/RadioConfigRepository.kt b/app/src/main/java/com/geeksville/mesh/repository/datastore/RadioConfigRepository.kt index b22ec9f5..80a4553a 100644 --- a/app/src/main/java/com/geeksville/mesh/repository/datastore/RadioConfigRepository.kt +++ b/app/src/main/java/com/geeksville/mesh/repository/datastore/RadioConfigRepository.kt @@ -57,7 +57,6 @@ class RadioConfigRepository @Inject constructor( val nodeDBbyNum: StateFlow> get() = nodeDB.nodeDBbyNum suspend fun upsert(node: NodeInfo) = nodeDB.upsert(node) - suspend fun clearNodeDB() = nodeDB.clearNodeDB() suspend fun installNodeDB(mi: MyNodeInfo, nodes: List) { nodeDB.installNodeDB(mi, nodes) } diff --git a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt index dc1694e3..f7e85632 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt @@ -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() }