mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-31 14:27:57 +01:00 
			
		
		
		
	Tweak library view (#8240)
- Move category join to improve performance - Move bookmark calculation into query - Move unread calculation into domain
This commit is contained in:
		| @@ -28,8 +28,8 @@ val mangaMapper: (Long, Long, String, String?, String?, String?, List<String>?, | ||||
|         ) | ||||
|     } | ||||
|  | ||||
| val libraryManga: (Long, Long, String, String?, String?, String?, List<String>?, String, Long, String?, Boolean, Long?, Long?, Boolean, Long, Long, Long, Long, UpdateStrategy, Long, Long, Long, Long, Long, Long) -> LibraryManga = | ||||
|     { id, source, url, artist, author, description, genre, title, status, thumbnailUrl, favorite, lastUpdate, nextUpdate, initialized, viewerFlags, chapterFlags, coverLastModified, dateAdded, updateStrategy, unreadCount, readCount, latestUpload, chapterFetchedAt, lastRead, category -> | ||||
| val libraryManga: (Long, Long, String, String?, String?, String?, List<String>?, String, Long, String?, Boolean, Long?, Long?, Boolean, Long, Long, Long, Long, UpdateStrategy, Long, Long, Long, Long, Long, Long, Long) -> LibraryManga = | ||||
|     { id, source, url, artist, author, description, genre, title, status, thumbnailUrl, favorite, lastUpdate, nextUpdate, initialized, viewerFlags, chapterFlags, coverLastModified, dateAdded, updateStrategy, totalCount, readCount, latestUpload, chapterFetchedAt, lastRead, bookmarkCount, category -> | ||||
|         LibraryManga( | ||||
|             manga = mangaMapper( | ||||
|                 id, | ||||
| @@ -53,8 +53,9 @@ val libraryManga: (Long, Long, String, String?, String?, String?, List<String>?, | ||||
|                 updateStrategy, | ||||
|             ), | ||||
|             category = category, | ||||
|             unreadCount = unreadCount, | ||||
|             totalChapters = totalCount, | ||||
|             readCount = readCount, | ||||
|             bookmarkCount = bookmarkCount, | ||||
|             latestUpload = latestUpload, | ||||
|             chapterFetchedAt = chapterFetchedAt, | ||||
|             lastRead = lastRead, | ||||
|   | ||||
| @@ -19,7 +19,6 @@ import eu.kanade.domain.category.interactor.SetMangaCategories | ||||
| import eu.kanade.domain.category.interactor.SetSortModeForCategory | ||||
| import eu.kanade.domain.category.interactor.UpdateCategory | ||||
| import eu.kanade.domain.category.repository.CategoryRepository | ||||
| import eu.kanade.domain.chapter.interactor.GetBookmarkedChaptersByMangaId | ||||
| import eu.kanade.domain.chapter.interactor.GetChapter | ||||
| import eu.kanade.domain.chapter.interactor.GetChapterByMangaId | ||||
| import eu.kanade.domain.chapter.interactor.SetMangaDefaultChapterFlags | ||||
| @@ -111,7 +110,6 @@ class DomainModule : InjektModule { | ||||
|         addSingletonFactory<ChapterRepository> { ChapterRepositoryImpl(get()) } | ||||
|         addFactory { GetChapter(get()) } | ||||
|         addFactory { GetChapterByMangaId(get()) } | ||||
|         addFactory { GetBookmarkedChaptersByMangaId(get()) } | ||||
|         addFactory { UpdateChapter(get()) } | ||||
|         addFactory { SetReadStatus(get(), get(), get(), get()) } | ||||
|         addFactory { ShouldUpdateDbChapter() } | ||||
|   | ||||
| @@ -1,20 +0,0 @@ | ||||
| package eu.kanade.domain.chapter.interactor | ||||
|  | ||||
| import eu.kanade.domain.chapter.model.Chapter | ||||
| import eu.kanade.domain.chapter.repository.ChapterRepository | ||||
| import eu.kanade.tachiyomi.util.system.logcat | ||||
| import logcat.LogPriority | ||||
|  | ||||
| class GetBookmarkedChaptersByMangaId( | ||||
|     private val chapterRepository: ChapterRepository, | ||||
| ) { | ||||
|  | ||||
|     suspend fun await(mangaId: Long): List<Chapter> { | ||||
|         return try { | ||||
|             chapterRepository.getBookmarkedChaptersByMangaId(mangaId) | ||||
|         } catch (e: Exception) { | ||||
|             logcat(LogPriority.ERROR, e) | ||||
|             emptyList() | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -5,15 +5,20 @@ import eu.kanade.domain.manga.model.Manga | ||||
| data class LibraryManga( | ||||
|     val manga: Manga, | ||||
|     val category: Long, | ||||
|     val unreadCount: Long, | ||||
|     val totalChapters: Long, | ||||
|     val readCount: Long, | ||||
|     val bookmarkCount: Long, | ||||
|     val latestUpload: Long, | ||||
|     val chapterFetchedAt: Long, | ||||
|     val lastRead: Long, | ||||
| ) { | ||||
|     val id: Long = manga.id | ||||
|  | ||||
|     val totalChapters = readCount + unreadCount | ||||
|     val unreadCount | ||||
|         get() = totalChapters - readCount | ||||
|  | ||||
|     val hasBookmarks | ||||
|         get() = bookmarkCount > 0 | ||||
|  | ||||
|     val hasStarted = readCount > 0 | ||||
| } | ||||
|   | ||||
| @@ -19,7 +19,6 @@ import eu.kanade.domain.base.BasePreferences | ||||
| import eu.kanade.domain.category.interactor.GetCategories | ||||
| import eu.kanade.domain.category.interactor.SetMangaCategories | ||||
| import eu.kanade.domain.category.model.Category | ||||
| import eu.kanade.domain.chapter.interactor.GetBookmarkedChaptersByMangaId | ||||
| import eu.kanade.domain.chapter.interactor.GetChapterByMangaId | ||||
| import eu.kanade.domain.chapter.interactor.SetReadStatus | ||||
| import eu.kanade.domain.chapter.model.toDbChapter | ||||
| @@ -55,7 +54,6 @@ import kotlinx.coroutines.flow.Flow | ||||
| import kotlinx.coroutines.flow.collectLatest | ||||
| import kotlinx.coroutines.flow.combine | ||||
| import kotlinx.coroutines.flow.map | ||||
| import kotlinx.coroutines.runBlocking | ||||
| import rx.Observable | ||||
| import rx.android.schedulers.AndroidSchedulers | ||||
| import rx.schedulers.Schedulers | ||||
| @@ -84,7 +82,6 @@ class LibraryPresenter( | ||||
|     private val getLibraryManga: GetLibraryManga = Injekt.get(), | ||||
|     private val getTracks: GetTracks = Injekt.get(), | ||||
|     private val getCategories: GetCategories = Injekt.get(), | ||||
|     private val getBookmarkedChaptersByMangaId: GetBookmarkedChaptersByMangaId = Injekt.get(), | ||||
|     private val getChapterByMangaId: GetChapterByMangaId = Injekt.get(), | ||||
|     private val setReadStatus: SetReadStatus = Injekt.get(), | ||||
|     private val updateManga: UpdateManga = Injekt.get(), | ||||
| @@ -218,14 +215,13 @@ class LibraryPresenter( | ||||
|  | ||||
|         val filterFnBookmarked: (LibraryItem) -> Boolean = bookmarked@{ item -> | ||||
|             if (filterBookmarked == State.IGNORE.value) return@bookmarked true | ||||
|             return@bookmarked runBlocking { | ||||
|                 val isBookmarked = getBookmarkedChaptersByMangaId.await(item.libraryManga.manga.id).isNotEmpty() | ||||
|  | ||||
|                 return@runBlocking if (filterBookmarked == State.INCLUDE.value) { | ||||
|                     isBookmarked | ||||
|                 } else { | ||||
|                     !isBookmarked | ||||
|                 } | ||||
|             val hasBookmarks = item.libraryManga.hasBookmarks | ||||
|  | ||||
|             return@bookmarked if (filterBookmarked == State.INCLUDE.value) { | ||||
|                 hasBookmarks | ||||
|             } else { | ||||
|                 !hasBookmarks | ||||
|             } | ||||
|         } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user