New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hygiene: clean up code in PageAvailableOfflineHandler #4651
Conversation
app/src/main/java/org/wikipedia/page/PageAvailableOfflineHandler.kt
Outdated
Show resolved
Hide resolved
}) { | ||
val readingListPage = withContext(Dispatchers.IO) { AppDatabase.instance.readingListPageDao().findPageInAnyList(pageTitle) } | ||
val readingListPage = AppDatabase.instance.readingListPageDao().findPageInAnyList(pageTitle) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this might still need to be wrapped in withContext(Dispatchers.IO)
. The function findPageInAnyList()
doesn't suspend, so it will run on the default dispatcher of the scope (Main).
The way this is currently written, it doesn't need to be a coroutine (there's nothing that suspend
s).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one tiny thing, sorry!
@@ -130,7 +136,7 @@ interface ReadingListPageDao { | |||
updateThumbAndDescriptionByName(pageProto.lang, pageProto.apiTitle, thumbUrl, description) | |||
} | |||
|
|||
fun findPageInAnyList(title: PageTitle): ReadingListPage? { | |||
suspend fun findPageInAnyList(title: PageTitle): ReadingListPage? { | |||
return getPageByParams( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The getPageByParams
function also needs to be suspend
, since that's where Room actually does its job.
The process only needs the
Dispatchers.IO
and there's no need to applywithContext()
and an additionalrun{}
inCoroutineExceptionHandler
block.