From 0ddcf0b4ab44dc045cc6dde48af8f02059fb8dc6 Mon Sep 17 00:00:00 2001 From: Simon Marquis Date: Sun, 27 Aug 2023 11:02:11 +0200 Subject: [PATCH] Remove unnecessary dispatcher switch in `DefaultRecentSearchRepository` As mentioned in the following discussion: https://github.com/android/nowinandroid/discussions/818 Room already takes care of switching dispatchers if the DAO method is correctly annotated with the `suspend` modifier. --- .../DefaultRecentSearchRepository.kt | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/DefaultRecentSearchRepository.kt b/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/DefaultRecentSearchRepository.kt index 983c6af3e..702c2dcd2 100644 --- a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/DefaultRecentSearchRepository.kt +++ b/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/DefaultRecentSearchRepository.kt @@ -20,28 +20,21 @@ import com.google.samples.apps.nowinandroid.core.data.model.RecentSearchQuery import com.google.samples.apps.nowinandroid.core.data.model.asExternalModel import com.google.samples.apps.nowinandroid.core.database.dao.RecentSearchQueryDao import com.google.samples.apps.nowinandroid.core.database.model.RecentSearchQueryEntity -import com.google.samples.apps.nowinandroid.core.network.Dispatcher -import com.google.samples.apps.nowinandroid.core.network.NiaDispatchers.IO -import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map -import kotlinx.coroutines.withContext import kotlinx.datetime.Clock import javax.inject.Inject class DefaultRecentSearchRepository @Inject constructor( private val recentSearchQueryDao: RecentSearchQueryDao, - @Dispatcher(IO) private val ioDispatcher: CoroutineDispatcher, ) : RecentSearchRepository { override suspend fun insertOrReplaceRecentSearch(searchQuery: String) { - withContext(ioDispatcher) { - recentSearchQueryDao.insertOrReplaceRecentSearchQuery( - RecentSearchQueryEntity( - query = searchQuery, - queriedDate = Clock.System.now(), - ), - ) - } + recentSearchQueryDao.insertOrReplaceRecentSearchQuery( + RecentSearchQueryEntity( + query = searchQuery, + queriedDate = Clock.System.now(), + ), + ) } override fun getRecentSearchQueries(limit: Int): Flow> =