Significantly improve browsing speed (near instantaneous) (#1946)
(cherry picked from commit c8ffabc84a096207c1997ab69fc86176f3b53f00) # Conflicts: # CHANGELOG.md # app/src/main/java/eu/kanade/domain/manga/model/Manga.kt # app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreenModel.kt # data/src/main/java/tachiyomi/data/manga/MangaRepositoryImpl.kt # data/src/main/java/tachiyomi/data/source/SourcePagingSource.kt # data/src/main/sqldelight/tachiyomi/data/mangas.sq # domain/src/main/java/tachiyomi/domain/manga/interactor/NetworkToLocalManga.kt # domain/src/main/java/tachiyomi/domain/manga/repository/MangaRepository.kt # domain/src/main/java/tachiyomi/domain/source/repository/SourceRepository.kt
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package mihon.domain.manga.model
|
||||
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import tachiyomi.domain.manga.model.Manga
|
||||
|
||||
fun SManga.toDomainManga(sourceId: Long): Manga {
|
||||
return Manga.create().copy(
|
||||
url = url,
|
||||
// SY -->
|
||||
ogTitle = title,
|
||||
ogArtist = artist,
|
||||
ogAuthor = author,
|
||||
ogDescription = description,
|
||||
ogGenre = getGenres(),
|
||||
ogStatus = status.toLong(),
|
||||
ogThumbnailUrl = thumbnail_url,
|
||||
// SY <--
|
||||
updateStrategy = update_strategy,
|
||||
initialized = initialized,
|
||||
source = sourceId,
|
||||
)
|
||||
}
|
||||
@@ -7,29 +7,11 @@ class NetworkToLocalManga(
|
||||
private val mangaRepository: MangaRepository,
|
||||
) {
|
||||
|
||||
suspend fun await(manga: Manga): Manga {
|
||||
val localManga = getManga(manga.url, manga.source)
|
||||
return when {
|
||||
localManga == null -> {
|
||||
val id = insertManga(manga)
|
||||
manga.copy(id = id!!)
|
||||
}
|
||||
!localManga.favorite -> {
|
||||
// if the manga isn't a favorite, set its display title from source
|
||||
// if it later becomes a favorite, updated title will go to db
|
||||
localManga.copy(/* SY --> */ogTitle/* SY <-- */ = manga.title)
|
||||
}
|
||||
else -> {
|
||||
localManga
|
||||
}
|
||||
}
|
||||
suspend operator fun invoke(manga: Manga): Manga {
|
||||
return mangaRepository.insertNetworkManga(listOf(manga)).single()
|
||||
}
|
||||
|
||||
private suspend fun getManga(url: String, sourceId: Long): Manga? {
|
||||
return mangaRepository.getMangaByUrlAndSourceId(url, sourceId)
|
||||
}
|
||||
|
||||
private suspend fun insertManga(manga: Manga): Long? {
|
||||
return mangaRepository.insert(manga)
|
||||
suspend operator fun invoke(manga: List<Manga>): List<Manga> {
|
||||
return mangaRepository.insertNetworkManga(manga)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,12 +33,12 @@ interface MangaRepository {
|
||||
|
||||
suspend fun setMangaCategories(mangaId: Long, categoryIds: List<Long>)
|
||||
|
||||
suspend fun insert(manga: Manga): Long?
|
||||
|
||||
suspend fun update(update: MangaUpdate): Boolean
|
||||
|
||||
suspend fun updateAll(mangaUpdates: List<MangaUpdate>): Boolean
|
||||
|
||||
suspend fun insertNetworkManga(manga: List<Manga>): List<Manga>
|
||||
|
||||
// SY -->
|
||||
suspend fun getMangaBySourceId(sourceId: Long): List<Manga>
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package tachiyomi.domain.source.interactor
|
||||
|
||||
import eu.kanade.tachiyomi.source.model.FilterList
|
||||
import tachiyomi.domain.source.repository.SourcePagingSourceType
|
||||
import tachiyomi.domain.source.repository.SourcePagingSource
|
||||
import tachiyomi.domain.source.repository.SourceRepository
|
||||
|
||||
class GetRemoteManga(
|
||||
private val repository: SourceRepository,
|
||||
) {
|
||||
|
||||
fun subscribe(sourceId: Long, query: String, filterList: FilterList): SourcePagingSourceType {
|
||||
operator fun invoke(sourceId: Long, query: String, filterList: FilterList): SourcePagingSource {
|
||||
return when (query) {
|
||||
QUERY_POPULAR -> repository.getPopular(sourceId)
|
||||
QUERY_LATEST -> repository.getLatest(sourceId)
|
||||
|
||||
@@ -2,13 +2,13 @@ package tachiyomi.domain.source.repository
|
||||
|
||||
import androidx.paging.PagingSource
|
||||
import eu.kanade.tachiyomi.source.model.FilterList
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import exh.metadata.metadata.RaisedSearchMetadata
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import tachiyomi.domain.manga.model.Manga
|
||||
import tachiyomi.domain.source.model.Source
|
||||
import tachiyomi.domain.source.model.SourceWithCount
|
||||
|
||||
typealias SourcePagingSourceType = PagingSource<Long, /*SY --> */ Pair<SManga, RaisedSearchMetadata?>/*SY <-- */>
|
||||
typealias SourcePagingSource = PagingSource<Long, /*SY --> */ Pair<Manga, RaisedSearchMetadata?>/*SY <-- */>
|
||||
|
||||
interface SourceRepository {
|
||||
|
||||
@@ -20,9 +20,9 @@ interface SourceRepository {
|
||||
|
||||
fun getSourcesWithNonLibraryManga(): Flow<List<SourceWithCount>>
|
||||
|
||||
fun search(sourceId: Long, query: String, filterList: FilterList): SourcePagingSourceType
|
||||
fun search(sourceId: Long, query: String, filterList: FilterList): SourcePagingSource
|
||||
|
||||
fun getPopular(sourceId: Long): SourcePagingSourceType
|
||||
fun getPopular(sourceId: Long): SourcePagingSource
|
||||
|
||||
fun getLatest(sourceId: Long): SourcePagingSourceType
|
||||
fun getLatest(sourceId: Long): SourcePagingSource
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user