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:
arkon 2023-05-28 16:48:22 -04:00 committed by Jobobby04
parent 98697566e3
commit a90eb778d8
8 changed files with 41 additions and 24 deletions

View File

@ -13,6 +13,7 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Slider import androidx.compose.material3.Slider
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
@ -28,6 +29,7 @@ import eu.kanade.presentation.components.TriStateItem
import eu.kanade.presentation.util.collectAsState import eu.kanade.presentation.util.collectAsState
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.library.LibrarySettingsScreenModel import eu.kanade.tachiyomi.ui.library.LibrarySettingsScreenModel
import kotlinx.coroutines.flow.map
import tachiyomi.domain.category.model.Category import tachiyomi.domain.category.model.Category
import tachiyomi.domain.library.model.LibraryDisplayMode import tachiyomi.domain.library.model.LibraryDisplayMode
import tachiyomi.domain.library.model.LibraryGroup import tachiyomi.domain.library.model.LibraryGroup

View File

@ -248,7 +248,6 @@ class WebtoonPageHolder(
} }
private fun onStripSplit(imageStream: BufferedInputStream): InputStream { private fun onStripSplit(imageStream: BufferedInputStream): InputStream {
try { try {
// If we have reached this point [page] and its stream shouldn't be null // If we have reached this point [page] and its stream shouldn't be null
val page = page!! val page = page!!

View File

@ -90,6 +90,6 @@ class AndroidDatabaseHandler(
// SY --> // SY -->
fun getLibraryQuery(condition: String = "M.favorite = 1") = LibraryQuery(driver, condition) fun getLibraryQuery(condition: String = "M.favorite = 1") = LibraryQuery(driver, condition)
fun getUpdatesQuery(after: Long) = UpdatesQuery(driver, after) fun getUpdatesQuery(after: Long, limit: Long) = UpdatesQuery(driver, after, limit)
// SY <-- // SY <--
} }

View File

@ -26,7 +26,7 @@ private val mapper = { cursor: SqlCursor ->
) )
} }
class UpdatesQuery(val driver: SqlDriver, val after: Long) : Query<UpdatesView>(copyOnWriteList(), mapper) { class UpdatesQuery(val driver: SqlDriver, val after: Long, val limit: Long) : Query<UpdatesView>(copyOnWriteList(), mapper) {
override fun execute(): SqlCursor { override fun execute(): SqlCursor {
return driver.executeQuery( return driver.executeQuery(
null, null,
@ -79,11 +79,13 @@ class UpdatesQuery(val driver: SqlDriver, val after: Long) : Query<UpdatesView>(
WHERE favorite = 1 AND source = $MERGED_SOURCE_ID WHERE favorite = 1 AND source = $MERGED_SOURCE_ID
AND date_fetch > date_added AND date_fetch > date_added
AND dateUpload > :after AND dateUpload > :after
ORDER BY datefetch DESC; ORDER BY datefetch DESC
LIMIT :limit;
""".trimIndent(), """.trimIndent(),
1, 2,
binders = { binders = {
bindLong(1, after) bindLong(1, after)
bindLong(2, limit)
}, },
) )
} }

View File

@ -21,11 +21,11 @@ class UpdatesRepositoryImpl(
} }
} }
override fun subscribeAll(after: Long): Flow<List<UpdatesWithRelations>> { override fun subscribeAll(after: Long, limit: Long): Flow<List<UpdatesWithRelations>> {
return databaseHandler.subscribeToList { return databaseHandler.subscribeToList {
updatesViewQueries.updates(after, updateWithRelationMapper) updatesViewQueries.getRecentUpdates(after, limit, updateWithRelationMapper)
}.map { }.map {
databaseHandler.awaitList { (databaseHandler as AndroidDatabaseHandler).getUpdatesQuery(after) } databaseHandler.awaitList { (databaseHandler as AndroidDatabaseHandler).getUpdatesQuery(after, limit) }
.map(updatesViewMapper) .map(updatesViewMapper)
} }
} }

View File

@ -20,10 +20,11 @@ WHERE favorite = 1
AND date_fetch > date_added AND date_fetch > date_added
ORDER BY date_fetch DESC; ORDER BY date_fetch DESC;
updates: getRecentUpdates:
SELECT * SELECT *
FROM updatesView FROM updatesView
WHERE dateUpload > :after; WHERE dateUpload > :after
LIMIT :limit;
getUpdatesByReadStatus: getUpdatesByReadStatus:
SELECT * SELECT *

View File

@ -2,6 +2,8 @@ package tachiyomi.domain.updates.interactor
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.retry import kotlinx.coroutines.flow.retry
import tachiyomi.domain.updates.model.UpdatesWithRelations import tachiyomi.domain.updates.model.UpdatesWithRelations
import tachiyomi.domain.updates.repository.UpdatesRepository import tachiyomi.domain.updates.repository.UpdatesRepository
@ -13,26 +15,37 @@ class GetUpdates(
) { ) {
suspend fun await(read: Boolean, after: Long): List<UpdatesWithRelations> { 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(calendar: Calendar): Flow<List<UpdatesWithRelations>> {
return repository.subscribeAll(calendar.time.time, limit = 250)
fun subscribe(after: Long): Flow<List<UpdatesWithRelations>> {
return repository.subscribeAll(after)
// SY --> // SY -->
.retry { .catchNPE()
if (it is NullPointerException) {
delay(5.seconds)
true
} else {
false
}
}
// SY <-- // SY <--
} }
fun subscribe(read: Boolean, after: Long): Flow<List<UpdatesWithRelations>> { fun subscribe(read: Boolean, after: Long): Flow<List<UpdatesWithRelations>> {
return repository.subscribeWithRead(read, after) 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 <--
} }

View File

@ -7,7 +7,7 @@ interface UpdatesRepository {
suspend fun awaitWithRead(read: Boolean, after: Long): List<UpdatesWithRelations> 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>> fun subscribeWithRead(read: Boolean, after: Long): Flow<List<UpdatesWithRelations>>
} }