-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathpatch_utils.diff
More file actions
69 lines (62 loc) · 2.54 KB
/
patch_utils.diff
File metadata and controls
69 lines (62 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<<<<<<< SEARCH
=======
package eu.kanade.tachiyomi.source.online.utils
import com.github.michaelbull.result.getOrElse
import eu.kanade.tachiyomi.data.database.DatabaseHelper
import eu.kanade.tachiyomi.source.online.MangaDex
import eu.kanade.tachiyomi.util.system.executeOnIO
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope
import org.nekomanga.domain.site.MangaDexPreferences
suspend fun getBlockedScanlatorGroupUUIDs(
mangaDexPreferences: MangaDexPreferences,
db: DatabaseHelper,
mangaDex: MangaDex
): List<String> {
val blockedGroupNames = mangaDexPreferences.blockedGroups().get().toList()
return coroutineScope {
val chunks = blockedGroupNames.chunked(900)
val existingGroups = chunks.flatMap { chunk ->
db.getScanlatorGroupsByNames(chunk).executeAsBlocking()
}
val existingGroupNames = existingGroups.map { it.name }.toSet()
val missingGroupNames = blockedGroupNames.filterNot { it in existingGroupNames }
val fetchedGroups =
missingGroupNames
.map { name -> async { mangaDex.getScanlatorGroup(group = name) } }
.awaitAll()
.mapNotNull { result -> result.getOrElse { null }?.toScanlatorGroupImpl() }
if (fetchedGroups.isNotEmpty()) {
db.insertScanlatorGroups(fetchedGroups).executeOnIO()
}
(existingGroups + fetchedGroups).map { it.uuid }
}
}
suspend fun getBlockedUploaderUUIDs(
mangaDexPreferences: MangaDexPreferences,
db: DatabaseHelper,
mangaDex: MangaDex
): List<String> {
val blockedUploaderNames = mangaDexPreferences.blockedUploaders().get().toList()
return coroutineScope {
val chunks = blockedUploaderNames.chunked(900)
val existingUploaders = chunks.flatMap { chunk ->
db.getUploadersByNames(chunk).executeAsBlocking()
}
val existingUploaderNames = existingUploaders.map { it.username }.toSet()
val missingUploaderNames = blockedUploaderNames.filterNot {
it in existingUploaderNames
}
val fetchedUploaders =
missingUploaderNames
.map { name -> async { mangaDex.getUploader(uploader = name) } }
.awaitAll()
.mapNotNull { result -> result.getOrElse { null }?.toUploaderImpl() }
if (fetchedUploaders.isNotEmpty()) {
db.insertUploader(fetchedUploaders).executeOnIO()
}
(existingUploaders + fetchedUploaders).map { it.uuid }
}
}
>>>>>>> REPLACE