mirror of
https://github.com/mihonapp/mihon.git
synced 2025-10-17 08:39:43 +02:00
Significantly improve browsing speed (near instantaneous) (#1946)
This commit is contained in:
20
domain/src/main/java/mihon/domain/manga/model/SManga.kt
Normal file
20
domain/src/main/java/mihon/domain/manga/model/SManga.kt
Normal file
@@ -0,0 +1,20 @@
|
||||
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,
|
||||
title = title,
|
||||
artist = artist,
|
||||
author = author,
|
||||
description = description,
|
||||
genre = getGenres(),
|
||||
status = status.toLong(),
|
||||
thumbnailUrl = thumbnail_url,
|
||||
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(title = 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,9 +33,9 @@ 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>
|
||||
}
|
||||
|
@@ -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,12 +2,12 @@ package tachiyomi.domain.source.repository
|
||||
|
||||
import androidx.paging.PagingSource
|
||||
import eu.kanade.tachiyomi.source.model.FilterList
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
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, SManga>
|
||||
typealias SourcePagingSource = PagingSource<Long, Manga>
|
||||
|
||||
interface SourceRepository {
|
||||
|
||||
@@ -19,9 +19,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