mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-13 00:05:08 +01:00
Optimize unread progess filters by using the library db query
This commit is contained in:
parent
a3c5cc2e91
commit
eed9e0c765
@ -6,6 +6,8 @@ class LibraryManga : MangaImpl() {
|
|||||||
|
|
||||||
var category: Int = 0
|
var category: Int = 0
|
||||||
|
|
||||||
|
var hasRead: Boolean = false
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun createBlank(categoryId: Int): LibraryManga = LibraryManga().apply {
|
fun createBlank(categoryId: Int): LibraryManga = LibraryManga().apply {
|
||||||
title = ""
|
title = ""
|
||||||
|
@ -37,15 +37,6 @@ interface MangaQueries : DbProvider {
|
|||||||
.withGetResolver(LibraryMangaGetResolver.INSTANCE)
|
.withGetResolver(LibraryMangaGetResolver.INSTANCE)
|
||||||
.prepare()
|
.prepare()
|
||||||
|
|
||||||
fun getLibraryManga(id: Long) = db.get()
|
|
||||||
.`object`(LibraryManga::class.java)
|
|
||||||
.withQuery(RawQuery.builder()
|
|
||||||
.query(getLibraryMangaQuery(id))
|
|
||||||
.observesTables(MangaTable.TABLE, ChapterTable.TABLE, MangaCategoryTable.TABLE, CategoryTable.TABLE)
|
|
||||||
.build())
|
|
||||||
.withGetResolver(LibraryMangaGetResolver.INSTANCE)
|
|
||||||
.prepare()
|
|
||||||
|
|
||||||
fun getFavoriteMangas() = db.get()
|
fun getFavoriteMangas() = db.get()
|
||||||
.listOfObjects(Manga::class.java)
|
.listOfObjects(Manga::class.java)
|
||||||
.withQuery(Query.builder()
|
.withQuery(Query.builder()
|
||||||
|
@ -12,7 +12,7 @@ import eu.kanade.tachiyomi.data.database.tables.MangaTable as Manga
|
|||||||
val libraryQuery = """
|
val libraryQuery = """
|
||||||
SELECT M.*, COALESCE(MC.${MangaCategory.COL_CATEGORY_ID}, 0) AS ${Manga.COL_CATEGORY}
|
SELECT M.*, COALESCE(MC.${MangaCategory.COL_CATEGORY_ID}, 0) AS ${Manga.COL_CATEGORY}
|
||||||
FROM (
|
FROM (
|
||||||
SELECT ${Manga.TABLE}.*, COALESCE(C.unread, 0) AS ${Manga.COL_UNREAD}
|
SELECT ${Manga.TABLE}.*, COALESCE(C.unread, 0) AS ${Manga.COL_UNREAD}, COALESCE(R.hasread, 0) AS ${Manga.COL_HAS_READ}
|
||||||
FROM ${Manga.TABLE}
|
FROM ${Manga.TABLE}
|
||||||
LEFT JOIN (
|
LEFT JOIN (
|
||||||
SELECT ${Chapter.COL_MANGA_ID}, COUNT(*) AS unread
|
SELECT ${Chapter.COL_MANGA_ID}, COUNT(*) AS unread
|
||||||
@ -21,6 +21,13 @@ val libraryQuery = """
|
|||||||
GROUP BY ${Chapter.COL_MANGA_ID}
|
GROUP BY ${Chapter.COL_MANGA_ID}
|
||||||
) AS C
|
) AS C
|
||||||
ON ${Manga.COL_ID} = C.${Chapter.COL_MANGA_ID}
|
ON ${Manga.COL_ID} = C.${Chapter.COL_MANGA_ID}
|
||||||
|
LEFT JOIN (
|
||||||
|
SELECT ${Chapter.COL_MANGA_ID}, COUNT(*) AS hasread
|
||||||
|
FROM ${Chapter.TABLE}
|
||||||
|
WHERE ${Chapter.COL_READ} = 1
|
||||||
|
GROUP BY ${Chapter.COL_MANGA_ID}
|
||||||
|
) AS R
|
||||||
|
ON ${Manga.COL_ID} = R.${Chapter.COL_MANGA_ID}
|
||||||
WHERE ${Manga.COL_FAVORITE} = 1
|
WHERE ${Manga.COL_FAVORITE} = 1
|
||||||
GROUP BY ${Manga.COL_ID}
|
GROUP BY ${Manga.COL_ID}
|
||||||
ORDER BY ${Manga.COL_TITLE}
|
ORDER BY ${Manga.COL_TITLE}
|
||||||
@ -30,27 +37,6 @@ val libraryQuery = """
|
|||||||
ON MC.${MangaCategory.COL_MANGA_ID} = M.${Manga.COL_ID}
|
ON MC.${MangaCategory.COL_MANGA_ID} = M.${Manga.COL_ID}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
fun getLibraryMangaQuery(id: Long) = """
|
|
||||||
SELECT M.*, COALESCE(MC.${MangaCategory.COL_CATEGORY_ID}, 0) AS ${Manga.COL_CATEGORY}
|
|
||||||
FROM (
|
|
||||||
SELECT ${Manga.TABLE}.*, COALESCE(C.unread, 0) AS ${Manga.COL_UNREAD}
|
|
||||||
FROM ${Manga.TABLE}
|
|
||||||
LEFT JOIN (
|
|
||||||
SELECT ${Chapter.COL_MANGA_ID}, COUNT(*) AS unread
|
|
||||||
FROM ${Chapter.TABLE}
|
|
||||||
WHERE ${Chapter.COL_READ} = 0
|
|
||||||
GROUP BY ${Chapter.COL_MANGA_ID}
|
|
||||||
) AS C
|
|
||||||
ON ${Manga.COL_ID} = C.${Chapter.COL_MANGA_ID}
|
|
||||||
WHERE ${Manga.COL_FAVORITE} = 1 AND ${Manga.COL_ID} = $id
|
|
||||||
GROUP BY ${Manga.COL_ID}
|
|
||||||
ORDER BY ${Manga.COL_TITLE}
|
|
||||||
) AS M
|
|
||||||
LEFT JOIN (
|
|
||||||
SELECT * FROM ${MangaCategory.TABLE}) AS MC
|
|
||||||
ON MC.${MangaCategory.COL_MANGA_ID} = M.${Manga.COL_ID}
|
|
||||||
"""
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query to get the recent chapters of manga from the library up to a date.
|
* Query to get the recent chapters of manga from the library up to a date.
|
||||||
*/
|
*/
|
||||||
|
@ -18,6 +18,7 @@ class LibraryMangaGetResolver : DefaultGetResolver<LibraryManga>(), BaseMangaGet
|
|||||||
mapBaseFromCursor(manga, cursor)
|
mapBaseFromCursor(manga, cursor)
|
||||||
manga.unread = cursor.getInt(cursor.getColumnIndex(MangaTable.COL_UNREAD))
|
manga.unread = cursor.getInt(cursor.getColumnIndex(MangaTable.COL_UNREAD))
|
||||||
manga.category = cursor.getInt(cursor.getColumnIndex(MangaTable.COL_CATEGORY))
|
manga.category = cursor.getInt(cursor.getColumnIndex(MangaTable.COL_CATEGORY))
|
||||||
|
manga.hasRead = cursor.getInt(cursor.getColumnIndex(MangaTable.COL_HAS_READ)) > 0
|
||||||
|
|
||||||
return manga
|
return manga
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,8 @@ object MangaTable {
|
|||||||
|
|
||||||
const val COL_UNREAD = "unread"
|
const val COL_UNREAD = "unread"
|
||||||
|
|
||||||
|
const val COL_HAS_READ = "has_read"
|
||||||
|
|
||||||
const val COL_CATEGORY = "category"
|
const val COL_CATEGORY = "category"
|
||||||
|
|
||||||
const val COL_HIDE_TITLE = "hideTitle"
|
const val COL_HIDE_TITLE = "hideTitle"
|
||||||
|
@ -227,12 +227,8 @@ class LibraryPresenter(
|
|||||||
if (filterUnread == STATE_EXCLUDE && item.manga.unread > 0) return false
|
if (filterUnread == STATE_EXCLUDE && item.manga.unread > 0) return false
|
||||||
|
|
||||||
// Filter for unread chapters
|
// Filter for unread chapters
|
||||||
if (filterUnread == 3 && (item.manga.unread == 0 || db.getChapters(item.manga)
|
if (filterUnread == 3 && !(item.manga.unread > 0 && !item.manga.hasRead)) return false
|
||||||
.executeAsBlocking().size != item.manga.unread)
|
if (filterUnread == 4 && !(item.manga.unread > 0 && item.manga.hasRead)) return false
|
||||||
) return false
|
|
||||||
if (filterUnread == 4 && (item.manga.unread == 0 || db.getChapters(item.manga)
|
|
||||||
.executeAsBlocking().size == item.manga.unread)
|
|
||||||
) return false
|
|
||||||
|
|
||||||
if (filterMangaType > 0) {
|
if (filterMangaType > 0) {
|
||||||
if (if (filterMangaType == Manga.TYPE_MANHWA) (filterMangaType != item.manga.mangaType() && filterMangaType != Manga.TYPE_WEBTOON)
|
if (if (filterMangaType == Manga.TYPE_MANHWA) (filterMangaType != item.manga.mangaType() && filterMangaType != Manga.TYPE_WEBTOON)
|
||||||
@ -654,21 +650,7 @@ class LibraryPresenter(
|
|||||||
|
|
||||||
/** Called when Library Service updates a manga, update the item as well */
|
/** Called when Library Service updates a manga, update the item as well */
|
||||||
fun updateManga(manga: LibraryManga) {
|
fun updateManga(manga: LibraryManga) {
|
||||||
scope.launch {
|
getLibrary()
|
||||||
val rawMap = allLibraryItems
|
|
||||||
val currentMap = libraryItems
|
|
||||||
val id = manga.id ?: return@launch
|
|
||||||
val dbManga = db.getLibraryManga(id).executeOnIO() ?: return@launch
|
|
||||||
arrayOf(rawMap, currentMap).forEach { map ->
|
|
||||||
map.forEach { item ->
|
|
||||||
if (item.manga.id == dbManga.id) {
|
|
||||||
item.manga.last_update = dbManga.last_update
|
|
||||||
item.manga.unread = dbManga.unread
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
getLibrary()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Undo the removal of the manga once in library */
|
/** Undo the removal of the manga once in library */
|
||||||
|
Loading…
Reference in New Issue
Block a user