Limit updates to 250 most recent chapters
Still limits to things within the past 3 months though. Closes #9554 (cherry picked from commit 4c65c2311e09bf5dcb77327c415a6fddd12123c5) # Conflicts: # data/src/main/java/tachiyomi/data/updates/UpdatesRepositoryImpl.kt # domain/src/main/java/tachiyomi/domain/updates/interactor/GetUpdates.kt
This commit is contained in:
@@ -2,6 +2,8 @@ package tachiyomi.domain.updates.interactor
|
||||
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.flow.retry
|
||||
import tachiyomi.domain.updates.model.UpdatesWithRelations
|
||||
import tachiyomi.domain.updates.repository.UpdatesRepository
|
||||
@@ -13,26 +15,37 @@ class GetUpdates(
|
||||
) {
|
||||
|
||||
suspend fun await(read: Boolean, after: Long): List<UpdatesWithRelations> {
|
||||
return repository.awaitWithRead(read, after)
|
||||
// SY -->
|
||||
return flow {
|
||||
emit(repository.awaitWithRead(read, after))
|
||||
}
|
||||
.catchNPE()
|
||||
.first()
|
||||
// SY <--
|
||||
}
|
||||
|
||||
fun subscribe(calendar: Calendar): Flow<List<UpdatesWithRelations>> = subscribe(calendar.time.time)
|
||||
|
||||
fun subscribe(after: Long): Flow<List<UpdatesWithRelations>> {
|
||||
return repository.subscribeAll(after)
|
||||
fun subscribe(calendar: Calendar): Flow<List<UpdatesWithRelations>> {
|
||||
return repository.subscribeAll(calendar.time.time, limit = 250)
|
||||
// SY -->
|
||||
.retry {
|
||||
if (it is NullPointerException) {
|
||||
delay(5.seconds)
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
.catchNPE()
|
||||
// SY <--
|
||||
}
|
||||
|
||||
fun subscribe(read: Boolean, after: Long): Flow<List<UpdatesWithRelations>> {
|
||||
return repository.subscribeWithRead(read, after)
|
||||
// SY -->
|
||||
.catchNPE()
|
||||
// SY <--
|
||||
}
|
||||
|
||||
// SY -->
|
||||
private fun <T> Flow<T>.catchNPE() = retry {
|
||||
if (it is NullPointerException) {
|
||||
delay(5.seconds)
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
// SY <--
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ interface UpdatesRepository {
|
||||
|
||||
suspend fun awaitWithRead(read: Boolean, after: Long): List<UpdatesWithRelations>
|
||||
|
||||
fun subscribeAll(after: Long): Flow<List<UpdatesWithRelations>>
|
||||
fun subscribeAll(after: Long, limit: Long): Flow<List<UpdatesWithRelations>>
|
||||
|
||||
fun subscribeWithRead(read: Boolean, after: Long): Flow<List<UpdatesWithRelations>>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user