Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Run db access on io thread (DEV) #1954

Merged
merged 5 commits into from Dec 18, 2020
Merged

Conversation

chiljamgossow
Copy link
Contributor

@chiljamgossow chiljamgossow commented Dec 18, 2020

db access on io thread
addresses review comment

@chiljamgossow chiljamgossow added the maintainers Tag pull requests created by maintainers label Dec 18, 2020
@chiljamgossow chiljamgossow added this to the 1.10.0 milestone Dec 18, 2020
@chiljamgossow chiljamgossow requested a review from a team December 18, 2020 16:14
@ralfgehrer ralfgehrer self-assigned this Dec 18, 2020
@sonarcloud
Copy link

sonarcloud bot commented Dec 18, 2020

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

Copy link
Contributor

@BMItr BMItr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really sure why this is necessary because room creates a co-routines itself when suspending.
Also calling launchIn on a Flow would make sense to me.

@chiljamgossow chiljamgossow merged commit c39c8c5 into release/1.10.x Dec 18, 2020
@chiljamgossow chiljamgossow deleted the feature/run-on-io branch December 18, 2020 17:10
@chiljamgossow
Copy link
Contributor Author

I did not find an issue here, both versions work fine.

@d4rken
Copy link
Member

d4rken commented Dec 18, 2020

There was confusion over the scopes(threads) being implicitly used. TLDR:

  • Room internally switches to a Room specific scope with extra (non-main) threads.
  • Live Data does not and executes on the main thread (scope)

The database query would not have been an issue but the sorting (any future repository operations) would be running on the main thread.
By expclitly telling livedata to run on a different context, as you did here, we avoid any situations where internal changes or sorting of large data sets lags the UI.

It could be discussed whether IO or Default would be the better dispatcher choice, but either has the desired effect.

All is okay 👍

@BMItr BMItr self-assigned this Dec 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
maintainers Tag pull requests created by maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants