mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 15:21:51 +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:
parent
2d19729869
commit
8d97b980e3
@ -27,7 +27,7 @@ android {
|
|||||||
applicationId = "eu.kanade.tachiyomi"
|
applicationId = "eu.kanade.tachiyomi"
|
||||||
minSdk = AndroidConfig.minSdk
|
minSdk = AndroidConfig.minSdk
|
||||||
targetSdk = AndroidConfig.targetSdk
|
targetSdk = AndroidConfig.targetSdk
|
||||||
versionCode = 87
|
versionCode = 88
|
||||||
versionName = "0.13.6"
|
versionName = "0.13.6"
|
||||||
|
|
||||||
buildConfigField("String", "COMMIT_COUNT", "\"${getCommitCount()}\"")
|
buildConfigField("String", "COMMIT_COUNT", "\"${getCommitCount()}\"")
|
||||||
|
@ -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 =
|
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, unreadCount, readCount, latestUpload, chapterFetchedAt, lastRead, category ->
|
{ 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(
|
LibraryManga(
|
||||||
manga = mangaMapper(
|
manga = mangaMapper(
|
||||||
id,
|
id,
|
||||||
@ -53,8 +53,9 @@ val libraryManga: (Long, Long, String, String?, String?, String?, List<String>?,
|
|||||||
updateStrategy,
|
updateStrategy,
|
||||||
),
|
),
|
||||||
category = category,
|
category = category,
|
||||||
unreadCount = unreadCount,
|
totalChapters = totalCount,
|
||||||
readCount = readCount,
|
readCount = readCount,
|
||||||
|
bookmarkCount = bookmarkCount,
|
||||||
latestUpload = latestUpload,
|
latestUpload = latestUpload,
|
||||||
chapterFetchedAt = chapterFetchedAt,
|
chapterFetchedAt = chapterFetchedAt,
|
||||||
lastRead = lastRead,
|
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.SetSortModeForCategory
|
||||||
import eu.kanade.domain.category.interactor.UpdateCategory
|
import eu.kanade.domain.category.interactor.UpdateCategory
|
||||||
import eu.kanade.domain.category.repository.CategoryRepository
|
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.GetChapter
|
||||||
import eu.kanade.domain.chapter.interactor.GetChapterByMangaId
|
import eu.kanade.domain.chapter.interactor.GetChapterByMangaId
|
||||||
import eu.kanade.domain.chapter.interactor.SetMangaDefaultChapterFlags
|
import eu.kanade.domain.chapter.interactor.SetMangaDefaultChapterFlags
|
||||||
@ -111,7 +110,6 @@ class DomainModule : InjektModule {
|
|||||||
addSingletonFactory<ChapterRepository> { ChapterRepositoryImpl(get()) }
|
addSingletonFactory<ChapterRepository> { ChapterRepositoryImpl(get()) }
|
||||||
addFactory { GetChapter(get()) }
|
addFactory { GetChapter(get()) }
|
||||||
addFactory { GetChapterByMangaId(get()) }
|
addFactory { GetChapterByMangaId(get()) }
|
||||||
addFactory { GetBookmarkedChaptersByMangaId(get()) }
|
|
||||||
addFactory { UpdateChapter(get()) }
|
addFactory { UpdateChapter(get()) }
|
||||||
addFactory { SetReadStatus(get(), get(), get(), get()) }
|
addFactory { SetReadStatus(get(), get(), get(), get()) }
|
||||||
addFactory { ShouldUpdateDbChapter() }
|
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(
|
data class LibraryManga(
|
||||||
val manga: Manga,
|
val manga: Manga,
|
||||||
val category: Long,
|
val category: Long,
|
||||||
val unreadCount: Long,
|
val totalChapters: Long,
|
||||||
val readCount: Long,
|
val readCount: Long,
|
||||||
|
val bookmarkCount: Long,
|
||||||
val latestUpload: Long,
|
val latestUpload: Long,
|
||||||
val chapterFetchedAt: Long,
|
val chapterFetchedAt: Long,
|
||||||
val lastRead: Long,
|
val lastRead: Long,
|
||||||
) {
|
) {
|
||||||
val id: Long = manga.id
|
val id: Long = manga.id
|
||||||
|
|
||||||
val totalChapters = readCount + unreadCount
|
val unreadCount
|
||||||
|
get() = totalChapters - readCount
|
||||||
|
|
||||||
|
val hasBookmarks
|
||||||
|
get() = bookmarkCount > 0
|
||||||
|
|
||||||
val hasStarted = readCount > 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.GetCategories
|
||||||
import eu.kanade.domain.category.interactor.SetMangaCategories
|
import eu.kanade.domain.category.interactor.SetMangaCategories
|
||||||
import eu.kanade.domain.category.model.Category
|
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.GetChapterByMangaId
|
||||||
import eu.kanade.domain.chapter.interactor.SetReadStatus
|
import eu.kanade.domain.chapter.interactor.SetReadStatus
|
||||||
import eu.kanade.domain.chapter.model.toDbChapter
|
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.collectLatest
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
import rx.android.schedulers.AndroidSchedulers
|
import rx.android.schedulers.AndroidSchedulers
|
||||||
import rx.schedulers.Schedulers
|
import rx.schedulers.Schedulers
|
||||||
@ -84,7 +82,6 @@ class LibraryPresenter(
|
|||||||
private val getLibraryManga: GetLibraryManga = Injekt.get(),
|
private val getLibraryManga: GetLibraryManga = Injekt.get(),
|
||||||
private val getTracks: GetTracks = Injekt.get(),
|
private val getTracks: GetTracks = Injekt.get(),
|
||||||
private val getCategories: GetCategories = Injekt.get(),
|
private val getCategories: GetCategories = Injekt.get(),
|
||||||
private val getBookmarkedChaptersByMangaId: GetBookmarkedChaptersByMangaId = Injekt.get(),
|
|
||||||
private val getChapterByMangaId: GetChapterByMangaId = Injekt.get(),
|
private val getChapterByMangaId: GetChapterByMangaId = Injekt.get(),
|
||||||
private val setReadStatus: SetReadStatus = Injekt.get(),
|
private val setReadStatus: SetReadStatus = Injekt.get(),
|
||||||
private val updateManga: UpdateManga = Injekt.get(),
|
private val updateManga: UpdateManga = Injekt.get(),
|
||||||
@ -218,14 +215,13 @@ class LibraryPresenter(
|
|||||||
|
|
||||||
val filterFnBookmarked: (LibraryItem) -> Boolean = bookmarked@{ item ->
|
val filterFnBookmarked: (LibraryItem) -> Boolean = bookmarked@{ item ->
|
||||||
if (filterBookmarked == State.IGNORE.value) return@bookmarked true
|
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) {
|
val hasBookmarks = item.libraryManga.hasBookmarks
|
||||||
isBookmarked
|
|
||||||
|
return@bookmarked if (filterBookmarked == State.INCLUDE.value) {
|
||||||
|
hasBookmarks
|
||||||
} else {
|
} else {
|
||||||
!isBookmarked
|
!hasBookmarks
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
31
app/src/main/sqldelight/migrations/22.sqm
Normal file
31
app/src/main/sqldelight/migrations/22.sqm
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
DROP VIEW libraryView;
|
||||||
|
|
||||||
|
CREATE VIEW libraryView AS
|
||||||
|
SELECT
|
||||||
|
M.*,
|
||||||
|
coalesce(C.total, 0) AS totalCount,
|
||||||
|
coalesce(C.readCount, 0) AS readCount,
|
||||||
|
coalesce(C.latestUpload, 0) AS latestUpload,
|
||||||
|
coalesce(C.fetchedAt, 0) AS chapterFetchedAt,
|
||||||
|
coalesce(C.lastRead, 0) AS lastRead,
|
||||||
|
coalesce(C.bookmarkCount, 0) AS bookmarkCount,
|
||||||
|
coalesce(MC.category_id, 0) AS category
|
||||||
|
FROM mangas M
|
||||||
|
LEFT JOIN(
|
||||||
|
SELECT
|
||||||
|
chapters.manga_id,
|
||||||
|
count(*) AS total,
|
||||||
|
sum(read) AS readCount,
|
||||||
|
coalesce(max(chapters.date_upload), 0) AS latestUpload,
|
||||||
|
coalesce(max(history.last_read), 0) AS lastRead,
|
||||||
|
coalesce(max(chapters.date_fetch), 0) AS fetchedAt,
|
||||||
|
sum(chapters.bookmark) AS bookmarkCount
|
||||||
|
FROM chapters
|
||||||
|
LEFT JOIN history
|
||||||
|
ON chapters._id = history.chapter_id
|
||||||
|
GROUP BY chapters.manga_id
|
||||||
|
) AS C
|
||||||
|
ON M._id = C.manga_id
|
||||||
|
LEFT JOIN mangas_categories AS MC
|
||||||
|
ON MC.manga_id = M._id
|
||||||
|
WHERE M.favorite = 1;
|
@ -1,15 +1,14 @@
|
|||||||
CREATE VIEW libraryView AS
|
CREATE VIEW libraryView AS
|
||||||
SELECT
|
SELECT
|
||||||
M.*,
|
M.*,
|
||||||
coalesce(C.total - C.readCount, 0) AS unreadCount,
|
coalesce(C.total, 0) AS totalCount,
|
||||||
coalesce(C.readCount, 0) AS readCount,
|
coalesce(C.readCount, 0) AS readCount,
|
||||||
coalesce(C.latestUpload, 0) AS latestUpload,
|
coalesce(C.latestUpload, 0) AS latestUpload,
|
||||||
coalesce(C.fetchedAt, 0) AS chapterFetchedAt,
|
coalesce(C.fetchedAt, 0) AS chapterFetchedAt,
|
||||||
coalesce(C.lastRead, 0) AS lastRead,
|
coalesce(C.lastRead, 0) AS lastRead,
|
||||||
COALESCE(MC.category_id, 0) AS category
|
coalesce(C.bookmarkCount, 0) AS bookmarkCount,
|
||||||
|
coalesce(MC.category_id, 0) AS category
|
||||||
FROM mangas M
|
FROM mangas M
|
||||||
LEFT JOIN mangas_categories AS MC
|
|
||||||
ON MC.manga_id = M._id
|
|
||||||
LEFT JOIN(
|
LEFT JOIN(
|
||||||
SELECT
|
SELECT
|
||||||
chapters.manga_id,
|
chapters.manga_id,
|
||||||
@ -17,13 +16,16 @@ LEFT JOIN(
|
|||||||
sum(read) AS readCount,
|
sum(read) AS readCount,
|
||||||
coalesce(max(chapters.date_upload), 0) AS latestUpload,
|
coalesce(max(chapters.date_upload), 0) AS latestUpload,
|
||||||
coalesce(max(history.last_read), 0) AS lastRead,
|
coalesce(max(history.last_read), 0) AS lastRead,
|
||||||
coalesce(max(chapters.date_fetch), 0) AS fetchedAt
|
coalesce(max(chapters.date_fetch), 0) AS fetchedAt,
|
||||||
|
sum(chapters.bookmark) AS bookmarkCount
|
||||||
FROM chapters
|
FROM chapters
|
||||||
LEFT JOIN history
|
LEFT JOIN history
|
||||||
ON chapters._id = history.chapter_id
|
ON chapters._id = history.chapter_id
|
||||||
GROUP BY chapters.manga_id
|
GROUP BY chapters.manga_id
|
||||||
) AS C
|
) AS C
|
||||||
ON M._id = C.manga_id
|
ON M._id = C.manga_id
|
||||||
|
LEFT JOIN mangas_categories AS MC
|
||||||
|
ON MC.manga_id = M._id
|
||||||
WHERE M.favorite = 1;
|
WHERE M.favorite = 1;
|
||||||
|
|
||||||
library:
|
library:
|
||||||
|
Loading…
Reference in New Issue
Block a user