Skip to content
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

Merged
merged 18 commits into from May 22, 2024

Conversation

cooltey
Copy link
Collaborator

@cooltey cooltey commented May 8, 2024

The process only needs the Dispatchers.IO and there's no need to apply withContext() and an additional run{} in CoroutineExceptionHandler block.

@cooltey cooltey added the Minor Minor stuff label May 8, 2024
Base automatically changed from fix-offline-leadimages to main May 10, 2024 21:26
}) {
val readingListPage = withContext(Dispatchers.IO) { AppDatabase.instance.readingListPageDao().findPageInAnyList(pageTitle) }
val readingListPage = AppDatabase.instance.readingListPageDao().findPageInAnyList(pageTitle)
Copy link
Member

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 suspends).

Copy link
Member

@dbrant dbrant left a 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(
Copy link
Member

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.

@dbrant dbrant merged commit 671f59a into main May 22, 2024
1 check passed
@dbrant dbrant deleted the hygiene-offline-handler branch May 22, 2024 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Minor Minor stuff
2 participants