mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
refactor(recents): Fully migrate recents to use SQLDelight, for real this time
This commit is contained in:
parent
0d9ffc2206
commit
a27c0edf13
4 changed files with 60 additions and 111 deletions
|
@ -55,8 +55,8 @@ data class MangaChapterHistory(val manga: Manga, val chapter: Chapter, val histo
|
|||
historyChapterId: Long?,
|
||||
historyLastRead: Long?,
|
||||
historyTimeRead: Long?,
|
||||
) = MangaChapterHistory(
|
||||
Manga.mapper(
|
||||
): MangaChapterHistory {
|
||||
val manga = Manga.mapper(
|
||||
id = mangaId,
|
||||
source = source,
|
||||
url = mangaUrl,
|
||||
|
@ -77,11 +77,13 @@ data class MangaChapterHistory(val manga: Manga, val chapter: Chapter, val histo
|
|||
filteredScanlators = filteredScanlators,
|
||||
updateStrategy = updateStrategy,
|
||||
coverLastModified = coverLastModified,
|
||||
),
|
||||
)
|
||||
|
||||
val chapter = try {
|
||||
chapterId?.let {
|
||||
Chapter.mapper(
|
||||
id = chapterId,
|
||||
mangaId = _mangaId!!,
|
||||
mangaId = _mangaId ?: mangaId,
|
||||
url = chapterUrl!!,
|
||||
name = name!!,
|
||||
scanlator = scanlator,
|
||||
|
@ -94,7 +96,10 @@ data class MangaChapterHistory(val manga: Manga, val chapter: Chapter, val histo
|
|||
dateFetch = dateFetch!!,
|
||||
dateUpload = dateUpload!!,
|
||||
)
|
||||
} ?: Chapter.create(),
|
||||
}
|
||||
} catch (_: NullPointerException) { null } ?: Chapter.create()
|
||||
|
||||
val history = try {
|
||||
historyId?.let {
|
||||
History.mapper(
|
||||
id = historyId,
|
||||
|
@ -102,12 +107,13 @@ data class MangaChapterHistory(val manga: Manga, val chapter: Chapter, val histo
|
|||
lastRead = historyLastRead,
|
||||
timeRead = historyTimeRead,
|
||||
)
|
||||
} ?: History.create().apply {
|
||||
(historyChapterId ?: chapterId)?.let { chapter_id = it }
|
||||
}
|
||||
} catch (_: NullPointerException) { null } ?: History.create().apply {
|
||||
historyLastRead?.let { last_read = it }
|
||||
historyTimeRead?.let { time_read = it }
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
return MangaChapterHistory(manga, chapter, history)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -142,35 +142,4 @@ interface HistoryQueries : DbProvider {
|
|||
.build(),
|
||||
)
|
||||
.prepare()
|
||||
|
||||
/**
|
||||
* Returns history of recent manga containing last read chapter in 25s
|
||||
* @param date recent date range
|
||||
* @offset offset the db by
|
||||
*/
|
||||
fun getAllRecentsTypes(
|
||||
search: String = "",
|
||||
includeRead: Boolean,
|
||||
endless: Boolean,
|
||||
offset: Int,
|
||||
isResuming: Boolean,
|
||||
) = db.get()
|
||||
.listOfObjects(MangaChapterHistory::class.java)
|
||||
.withQuery(
|
||||
RawQuery.builder()
|
||||
.query(
|
||||
getAllRecentsType(
|
||||
search.sqLite,
|
||||
includeRead,
|
||||
endless,
|
||||
offset,
|
||||
isResuming,
|
||||
),
|
||||
)
|
||||
// .args(date.time, startDate.time)
|
||||
.observesTables(HistoryTable.TABLE)
|
||||
.build(),
|
||||
)
|
||||
.withGetResolver(MangaChapterHistoryGetResolver.INSTANCE)
|
||||
.prepare()
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ import eu.kanade.tachiyomi.source.SourceManager
|
|||
import eu.kanade.tachiyomi.ui.base.presenter.BaseCoroutinePresenter
|
||||
import eu.kanade.tachiyomi.util.chapter.ChapterFilter
|
||||
import eu.kanade.tachiyomi.util.chapter.ChapterSort
|
||||
import eu.kanade.tachiyomi.util.system.executeOnIO
|
||||
import eu.kanade.tachiyomi.util.system.launchIO
|
||||
import eu.kanade.tachiyomi.util.system.launchUI
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
|
@ -172,8 +171,6 @@ class RecentsPresenter(
|
|||
var extraCount = 0
|
||||
val cReading: List<MangaChapterHistory> = when (viewType) {
|
||||
RecentsViewType.GroupedAll, RecentsViewType.UngroupedAll -> {
|
||||
// FIXME
|
||||
/*
|
||||
getRecents.awaitAll(
|
||||
showRead,
|
||||
true,
|
||||
|
@ -182,14 +179,6 @@ class RecentsPresenter(
|
|||
query,
|
||||
(if (isCustom) ENDLESS_LIMIT else pageOffset).toLong(),
|
||||
)
|
||||
*/
|
||||
db.getAllRecentsTypes(
|
||||
query,
|
||||
showRead,
|
||||
isEndless,
|
||||
if (isCustom) ENDLESS_LIMIT else pageOffset,
|
||||
!updatePageCount && !isOnFirstPage,
|
||||
).executeOnIO()
|
||||
}
|
||||
RecentsViewType.History -> {
|
||||
val items = if (groupChaptersHistory == GroupType.BySeries) {
|
||||
|
|
|
@ -62,33 +62,33 @@ AND (
|
|||
ORDER BY max_last_read.history_last_read DESC
|
||||
LIMIT :limit OFFSET :offset;
|
||||
|
||||
getRecentsAll: -- FIXME: This is insanity, require refactoring
|
||||
SELECT * FROM (
|
||||
getRecentsAll:
|
||||
SELECT R.* FROM (
|
||||
SELECT
|
||||
mangas.*,
|
||||
M.*,
|
||||
chapters.*,
|
||||
history.history_id AS history_id,
|
||||
history.history_chapter_id AS history_chapter_id,
|
||||
history.history_last_read AS history_last_read,
|
||||
history.history_time_read AS history_time_read
|
||||
FROM (
|
||||
SELECT mangas.*
|
||||
FROM mangas
|
||||
SELECT M2.*
|
||||
FROM mangas AS M2
|
||||
LEFT JOIN (
|
||||
SELECT manga_id, COUNT(*) AS unread
|
||||
FROM chapters
|
||||
WHERE read = 0
|
||||
GROUP BY manga_id
|
||||
) AS C
|
||||
ON _id = C.manga_id
|
||||
ON M2._id = C.manga_id
|
||||
WHERE (
|
||||
:include_read = 0 OR C.unread > 0
|
||||
)
|
||||
GROUP BY _id
|
||||
GROUP BY M2._id
|
||||
ORDER BY title
|
||||
) AS mangas
|
||||
) AS M
|
||||
JOIN chapters
|
||||
ON mangas._id = chapters.manga_id
|
||||
ON M._id = chapters.manga_id
|
||||
JOIN history
|
||||
ON chapters._id = history.history_chapter_id
|
||||
JOIN (
|
||||
|
@ -110,36 +110,21 @@ WHERE lower(title) LIKE '%' || :search || '%'
|
|||
AND (
|
||||
:apply_filter = 0 OR S.name IS NULL
|
||||
)
|
||||
)
|
||||
) AS R
|
||||
|
||||
UNION --
|
||||
|
||||
SELECT * FROM (
|
||||
SELECT R.* FROM (
|
||||
SELECT
|
||||
mangas.*,
|
||||
M.*,
|
||||
chapters.*,
|
||||
NULL AS history_id,
|
||||
NULL AS history_chapter_id,
|
||||
chapters.date_fetch AS history_last_read,
|
||||
NULL AS history_time_read
|
||||
FROM (
|
||||
SELECT mangas.*
|
||||
FROM mangas
|
||||
LEFT JOIN (
|
||||
SELECT manga_id, COUNT(*) AS unread
|
||||
FROM chapters
|
||||
WHERE read = 0
|
||||
GROUP BY manga_id
|
||||
) AS C2
|
||||
ON _id = C2.manga_id
|
||||
WHERE (
|
||||
:include_read = 0 OR C2.unread > 0
|
||||
)
|
||||
GROUP BY _id
|
||||
ORDER BY title
|
||||
) AS mangas
|
||||
FROM mangas AS M
|
||||
JOIN chapters
|
||||
ON mangas._id = chapters.manga_id
|
||||
ON M._id = chapters.manga_id
|
||||
JOIN history
|
||||
ON chapters._id = history.history_chapter_id
|
||||
JOIN (
|
||||
|
@ -147,8 +132,8 @@ JOIN (
|
|||
manga_id,
|
||||
chapters._id AS history_chapter_id,
|
||||
max(date_upload)
|
||||
FROM chapters JOIN mangas
|
||||
ON _id = manga_id
|
||||
FROM chapters JOIN mangas AS M2
|
||||
ON M2._id = manga_id
|
||||
WHERE read = 0
|
||||
GROUP BY manga_id
|
||||
) AS newest_chapter
|
||||
|
@ -162,19 +147,19 @@ AND lower(title) LIKE '%' || :search || '%'
|
|||
AND (
|
||||
:apply_filter = 0 OR S.name IS NULL
|
||||
)
|
||||
)
|
||||
) AS R
|
||||
|
||||
UNION --
|
||||
|
||||
SELECT * FROM (
|
||||
SELECT R.* FROM (
|
||||
SELECT
|
||||
mangas.*,
|
||||
M.*,
|
||||
chapters.*,
|
||||
NULL AS history_id,
|
||||
NULL AS history_chapter_id,
|
||||
mangas.date_added AS history_last_read,
|
||||
M.date_added AS history_last_read,
|
||||
NULL AS history_time_read
|
||||
FROM mangas
|
||||
FROM mangas AS M
|
||||
JOIN (
|
||||
SELECT
|
||||
NULL AS _id,
|
||||
|
@ -193,6 +178,6 @@ JOIN (
|
|||
) AS chapters
|
||||
WHERE favorite = 1
|
||||
AND lower(title) LIKE '%' || :search || '%'
|
||||
)
|
||||
) AS R
|
||||
ORDER BY history_last_read DESC
|
||||
LIMIT :limit OFFSET :offset;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue