Temporary fix checking for new chapters on large collections #584

This commit is contained in:
Koitharu
2023-12-19 17:32:12 +02:00
parent 40dde71a1d
commit 1076009572

View File

@@ -31,6 +31,7 @@ import javax.inject.Inject
import javax.inject.Provider
private const val NO_ID = 0L
private const val MAX_QUERY_IDS = 100
@Reusable
class TrackingRepository @Inject constructor(
@@ -65,7 +66,14 @@ class TrackingRepository @Inject constructor(
suspend fun getTracks(mangaList: Collection<Manga>): List<MangaTracking> {
val ids = mangaList.mapToSet { it.id }
val tracks = db.getTracksDao().findAll(ids).groupBy { it.mangaId }
val dao = db.getTracksDao()
val tracks = if (ids.size <= MAX_QUERY_IDS) {
dao.findAll(ids)
} else {
// TODO split tracks in the worker
ids.windowed(MAX_QUERY_IDS, MAX_QUERY_IDS, true)
.flatMap { dao.findAll(it) }
}.groupBy { it.mangaId }
val idSet = HashSet<Long>()
val result = ArrayList<MangaTracking>(mangaList.size)
for (item in mangaList) {