android / android/architecture-samples
[Data layer codelab] Small error in 'refresh()' method in Chapter 7
- Dominant language
- Kotlin
- Stars
- 45.8k
- Forks
- 11.9k
- PR merge metrics
- No merged PRs in 30d
Description
In chapter 7 "Create the Task Repository", and in the 2nd step of section "Save and refresh network data", the code block suggests we do
```kotlin
suspend fun refresh() {
val networkTasks = networkDataSource.loadTasks()
localDataSource.deleteAll()
val localTasks = withContext(dispatcher) {
networkTasks.toLocal()
}
localDataSource.upsertAll(networkTasks.toLocal()) // THIS IS THE ERROR
}
```
as you can see, localTasks is pointless here because you are doing the same thing in the erroneous line but you are also blocking the main thread. Instead, it should look like this
```kotlin
suspend fun refresh() {
val networkTasks = networkDataSource.loadTasks()
localDataSource.deleteAll()
val localTasks = withContext(dispatcher) {
networkTasks.toLocal()
}
localDataSource.upsertAll(localTasks) // CORRECTED LINE
}
```
Contributor guide
Research direction
Open Chapter 7, "Create the Task Repository," and the "Save and refresh network data" section. Review the refresh() code block and confirm that the existing localTasks value is used for upsertAll. Done means the codelab no longer repeats networkTasks.toLocal() outside the dispatcher context.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100