From 34225cdfe3de021235d5f4ffebf6234550f2f98f Mon Sep 17 00:00:00 2001 From: James Rich <2199651+jamesarich@users.noreply.github.com> Date: Wed, 10 Dec 2025 10:15:25 -0600 Subject: [PATCH] chore: Use repeatOnLifecycle for lifecycle-aware coroutine launch (#3952) Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com> --- .../org/meshtastic/core/data/repository/NodeRepository.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/data/src/main/kotlin/org/meshtastic/core/data/repository/NodeRepository.kt b/core/data/src/main/kotlin/org/meshtastic/core/data/repository/NodeRepository.kt index b245566ec..ccb246098 100644 --- a/core/data/src/main/kotlin/org/meshtastic/core/data/repository/NodeRepository.kt +++ b/core/data/src/main/kotlin/org/meshtastic/core/data/repository/NodeRepository.kt @@ -19,6 +19,7 @@ package org.meshtastic.core.data.repository import androidx.lifecycle.Lifecycle import androidx.lifecycle.coroutineScope +import androidx.lifecycle.repeatOnLifecycle import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted @@ -29,6 +30,7 @@ import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.mapLatest import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.stateIn +import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.meshtastic.core.data.datasource.NodeInfoReadDataSource import org.meshtastic.core.data.datasource.NodeInfoWriteDataSource @@ -56,8 +58,10 @@ constructor( ) { init { // Backfill denormalized name columns for existing nodes on startup - processLifecycle.coroutineScope.launchWhenCreated { - withContext(dispatchers.io) { nodeInfoWriteDataSource.backfillDenormalizedNames() } + processLifecycle.coroutineScope.launch { + processLifecycle.repeatOnLifecycle(Lifecycle.State.CREATED) { + withContext(dispatchers.io) { nodeInfoWriteDataSource.backfillDenormalizedNames() } + } } }