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?,
|
historyChapterId: Long?,
|
||||||
historyLastRead: Long?,
|
historyLastRead: Long?,
|
||||||
historyTimeRead: Long?,
|
historyTimeRead: Long?,
|
||||||
) = MangaChapterHistory(
|
): MangaChapterHistory {
|
||||||
Manga.mapper(
|
val manga = Manga.mapper(
|
||||||
id = mangaId,
|
id = mangaId,
|
||||||
source = source,
|
source = source,
|
||||||
url = mangaUrl,
|
url = mangaUrl,
|
||||||
|
@ -77,37 +77,43 @@ data class MangaChapterHistory(val manga: Manga, val chapter: Chapter, val histo
|
||||||
filteredScanlators = filteredScanlators,
|
filteredScanlators = filteredScanlators,
|
||||||
updateStrategy = updateStrategy,
|
updateStrategy = updateStrategy,
|
||||||
coverLastModified = coverLastModified,
|
coverLastModified = coverLastModified,
|
||||||
),
|
)
|
||||||
chapterId?.let {
|
|
||||||
Chapter.mapper(
|
val chapter = try {
|
||||||
id = chapterId,
|
chapterId?.let {
|
||||||
mangaId = _mangaId!!,
|
Chapter.mapper(
|
||||||
url = chapterUrl!!,
|
id = chapterId,
|
||||||
name = name!!,
|
mangaId = _mangaId ?: mangaId,
|
||||||
scanlator = scanlator,
|
url = chapterUrl!!,
|
||||||
read = read!!,
|
name = name!!,
|
||||||
bookmark = bookmark!!,
|
scanlator = scanlator,
|
||||||
lastPageRead = lastPageRead!!,
|
read = read!!,
|
||||||
pagesLeft = pagesLeft!!,
|
bookmark = bookmark!!,
|
||||||
chapterNumber = chapterNumber!!,
|
lastPageRead = lastPageRead!!,
|
||||||
sourceOrder = sourceOrder!!,
|
pagesLeft = pagesLeft!!,
|
||||||
dateFetch = dateFetch!!,
|
chapterNumber = chapterNumber!!,
|
||||||
dateUpload = dateUpload!!,
|
sourceOrder = sourceOrder!!,
|
||||||
)
|
dateFetch = dateFetch!!,
|
||||||
} ?: Chapter.create(),
|
dateUpload = dateUpload!!,
|
||||||
historyId?.let {
|
)
|
||||||
History.mapper(
|
}
|
||||||
id = historyId,
|
} catch (_: NullPointerException) { null } ?: Chapter.create()
|
||||||
chapterId = historyChapterId ?: chapterId ?: 0L,
|
|
||||||
lastRead = historyLastRead,
|
val history = try {
|
||||||
timeRead = historyTimeRead,
|
historyId?.let {
|
||||||
)
|
History.mapper(
|
||||||
} ?: History.create().apply {
|
id = historyId,
|
||||||
(historyChapterId ?: chapterId)?.let { chapter_id = it }
|
chapterId = historyChapterId ?: chapterId ?: 0L,
|
||||||
|
lastRead = historyLastRead,
|
||||||
|
timeRead = historyTimeRead,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} catch (_: NullPointerException) { null } ?: History.create().apply {
|
||||||
historyLastRead?.let { last_read = it }
|
historyLastRead?.let { last_read = it }
|
||||||
historyTimeRead?.let { time_read = it }
|
}
|
||||||
},
|
|
||||||
)
|
return MangaChapterHistory(manga, chapter, history)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -142,35 +142,4 @@ interface HistoryQueries : DbProvider {
|
||||||
.build(),
|
.build(),
|
||||||
)
|
)
|
||||||
.prepare()
|
.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.ui.base.presenter.BaseCoroutinePresenter
|
||||||
import eu.kanade.tachiyomi.util.chapter.ChapterFilter
|
import eu.kanade.tachiyomi.util.chapter.ChapterFilter
|
||||||
import eu.kanade.tachiyomi.util.chapter.ChapterSort
|
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.launchIO
|
||||||
import eu.kanade.tachiyomi.util.system.launchUI
|
import eu.kanade.tachiyomi.util.system.launchUI
|
||||||
import eu.kanade.tachiyomi.util.system.toast
|
import eu.kanade.tachiyomi.util.system.toast
|
||||||
|
@ -172,8 +171,6 @@ class RecentsPresenter(
|
||||||
var extraCount = 0
|
var extraCount = 0
|
||||||
val cReading: List<MangaChapterHistory> = when (viewType) {
|
val cReading: List<MangaChapterHistory> = when (viewType) {
|
||||||
RecentsViewType.GroupedAll, RecentsViewType.UngroupedAll -> {
|
RecentsViewType.GroupedAll, RecentsViewType.UngroupedAll -> {
|
||||||
// FIXME
|
|
||||||
/*
|
|
||||||
getRecents.awaitAll(
|
getRecents.awaitAll(
|
||||||
showRead,
|
showRead,
|
||||||
true,
|
true,
|
||||||
|
@ -182,14 +179,6 @@ class RecentsPresenter(
|
||||||
query,
|
query,
|
||||||
(if (isCustom) ENDLESS_LIMIT else pageOffset).toLong(),
|
(if (isCustom) ENDLESS_LIMIT else pageOffset).toLong(),
|
||||||
)
|
)
|
||||||
*/
|
|
||||||
db.getAllRecentsTypes(
|
|
||||||
query,
|
|
||||||
showRead,
|
|
||||||
isEndless,
|
|
||||||
if (isCustom) ENDLESS_LIMIT else pageOffset,
|
|
||||||
!updatePageCount && !isOnFirstPage,
|
|
||||||
).executeOnIO()
|
|
||||||
}
|
}
|
||||||
RecentsViewType.History -> {
|
RecentsViewType.History -> {
|
||||||
val items = if (groupChaptersHistory == GroupType.BySeries) {
|
val items = if (groupChaptersHistory == GroupType.BySeries) {
|
||||||
|
|
|
@ -62,33 +62,33 @@ AND (
|
||||||
ORDER BY max_last_read.history_last_read DESC
|
ORDER BY max_last_read.history_last_read DESC
|
||||||
LIMIT :limit OFFSET :offset;
|
LIMIT :limit OFFSET :offset;
|
||||||
|
|
||||||
getRecentsAll: -- FIXME: This is insanity, require refactoring
|
getRecentsAll:
|
||||||
SELECT * FROM (
|
SELECT R.* FROM (
|
||||||
SELECT
|
SELECT
|
||||||
mangas.*,
|
M.*,
|
||||||
chapters.*,
|
chapters.*,
|
||||||
history.history_id AS history_id,
|
history.history_id AS history_id,
|
||||||
history.history_chapter_id AS history_chapter_id,
|
history.history_chapter_id AS history_chapter_id,
|
||||||
history.history_last_read AS history_last_read,
|
history.history_last_read AS history_last_read,
|
||||||
history.history_time_read AS history_time_read
|
history.history_time_read AS history_time_read
|
||||||
FROM (
|
FROM (
|
||||||
SELECT mangas.*
|
SELECT M2.*
|
||||||
FROM mangas
|
FROM mangas AS M2
|
||||||
LEFT JOIN (
|
LEFT JOIN (
|
||||||
SELECT manga_id, COUNT(*) AS unread
|
SELECT manga_id, COUNT(*) AS unread
|
||||||
FROM chapters
|
FROM chapters
|
||||||
WHERE read = 0
|
WHERE read = 0
|
||||||
GROUP BY manga_id
|
GROUP BY manga_id
|
||||||
) AS C
|
) AS C
|
||||||
ON _id = C.manga_id
|
ON M2._id = C.manga_id
|
||||||
WHERE (
|
WHERE (
|
||||||
:include_read = 0 OR C.unread > 0
|
:include_read = 0 OR C.unread > 0
|
||||||
)
|
)
|
||||||
GROUP BY _id
|
GROUP BY M2._id
|
||||||
ORDER BY title
|
ORDER BY title
|
||||||
) AS mangas
|
) AS M
|
||||||
JOIN chapters
|
JOIN chapters
|
||||||
ON mangas._id = chapters.manga_id
|
ON M._id = chapters.manga_id
|
||||||
JOIN history
|
JOIN history
|
||||||
ON chapters._id = history.history_chapter_id
|
ON chapters._id = history.history_chapter_id
|
||||||
JOIN (
|
JOIN (
|
||||||
|
@ -110,36 +110,21 @@ WHERE lower(title) LIKE '%' || :search || '%'
|
||||||
AND (
|
AND (
|
||||||
:apply_filter = 0 OR S.name IS NULL
|
:apply_filter = 0 OR S.name IS NULL
|
||||||
)
|
)
|
||||||
)
|
) AS R
|
||||||
|
|
||||||
UNION --
|
UNION --
|
||||||
|
|
||||||
SELECT * FROM (
|
SELECT R.* FROM (
|
||||||
SELECT
|
SELECT
|
||||||
mangas.*,
|
M.*,
|
||||||
chapters.*,
|
chapters.*,
|
||||||
NULL AS history_id,
|
NULL AS history_id,
|
||||||
NULL AS history_chapter_id,
|
NULL AS history_chapter_id,
|
||||||
chapters.date_fetch AS history_last_read,
|
chapters.date_fetch AS history_last_read,
|
||||||
NULL AS history_time_read
|
NULL AS history_time_read
|
||||||
FROM (
|
FROM mangas AS M
|
||||||
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
|
|
||||||
JOIN chapters
|
JOIN chapters
|
||||||
ON mangas._id = chapters.manga_id
|
ON M._id = chapters.manga_id
|
||||||
JOIN history
|
JOIN history
|
||||||
ON chapters._id = history.history_chapter_id
|
ON chapters._id = history.history_chapter_id
|
||||||
JOIN (
|
JOIN (
|
||||||
|
@ -147,8 +132,8 @@ JOIN (
|
||||||
manga_id,
|
manga_id,
|
||||||
chapters._id AS history_chapter_id,
|
chapters._id AS history_chapter_id,
|
||||||
max(date_upload)
|
max(date_upload)
|
||||||
FROM chapters JOIN mangas
|
FROM chapters JOIN mangas AS M2
|
||||||
ON _id = manga_id
|
ON M2._id = manga_id
|
||||||
WHERE read = 0
|
WHERE read = 0
|
||||||
GROUP BY manga_id
|
GROUP BY manga_id
|
||||||
) AS newest_chapter
|
) AS newest_chapter
|
||||||
|
@ -162,19 +147,19 @@ AND lower(title) LIKE '%' || :search || '%'
|
||||||
AND (
|
AND (
|
||||||
:apply_filter = 0 OR S.name IS NULL
|
:apply_filter = 0 OR S.name IS NULL
|
||||||
)
|
)
|
||||||
)
|
) AS R
|
||||||
|
|
||||||
UNION --
|
UNION --
|
||||||
|
|
||||||
SELECT * FROM (
|
SELECT R.* FROM (
|
||||||
SELECT
|
SELECT
|
||||||
mangas.*,
|
M.*,
|
||||||
chapters.*,
|
chapters.*,
|
||||||
NULL AS history_id,
|
NULL AS history_id,
|
||||||
NULL AS history_chapter_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
|
NULL AS history_time_read
|
||||||
FROM mangas
|
FROM mangas AS M
|
||||||
JOIN (
|
JOIN (
|
||||||
SELECT
|
SELECT
|
||||||
NULL AS _id,
|
NULL AS _id,
|
||||||
|
@ -193,6 +178,6 @@ JOIN (
|
||||||
) AS chapters
|
) AS chapters
|
||||||
WHERE favorite = 1
|
WHERE favorite = 1
|
||||||
AND lower(title) LIKE '%' || :search || '%'
|
AND lower(title) LIKE '%' || :search || '%'
|
||||||
)
|
) AS R
|
||||||
ORDER BY history_last_read DESC
|
ORDER BY history_last_read DESC
|
||||||
LIMIT :limit OFFSET :offset;
|
LIMIT :limit OFFSET :offset;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue