chore(recents): Use sql query to filter scanlators

This commit is contained in:
Ahmad Ansori Palembani 2024-06-21 09:25:43 +07:00
parent 7341e10822
commit 7926590c22
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6
3 changed files with 36 additions and 7 deletions

View file

@ -8,17 +8,27 @@ import eu.kanade.tachiyomi.data.database.tables.HistoryTable as History
import eu.kanade.tachiyomi.data.database.tables.MangaCategoryTable as MangaCategory
import eu.kanade.tachiyomi.data.database.tables.MangaTable as Manga
// TODO: Migrate to SQLDelight
/**
* Query to get the recent chapters of manga from the library up to a date.
*/
fun getRecentsQuery(search: String, offset: Int, isResuming: Boolean) =
"""
SELECT ${Manga.TABLE}.${Manga.COL_URL} as mangaUrl, * FROM ${Manga.TABLE} JOIN ${Chapter.TABLE}
ON ${Manga.TABLE}.${Manga.COL_ID} = ${Chapter.TABLE}.${Chapter.COL_MANGA_ID}
WHERE ${Manga.COL_FAVORITE} = 1
AND ${Chapter.COL_DATE_FETCH} > ${Manga.COL_DATE_ADDED}
AND lower(${Manga.COL_TITLE}) LIKE '%$search%'
ORDER BY ${Chapter.COL_DATE_FETCH} DESC
SELECT
M.url AS mangaUrl,
M.*,
C.*
FROM mangas AS M
JOIN chapters AS C
ON M._id = C.manga_id
LEFT JOIN scanlators_view AS S
ON C.manga_id = S.manga_id
AND ifnull(C.scanlator, 'N/A') = ifnull(S.name, '/<INVALID>/')
WHERE M.favorite = 1
AND C.date_fetch > M.date_added
AND lower(M.title) LIKE '%$search%'
AND S.name IS NULL
ORDER BY C.date_fetch DESC
${limitAndOffset(true, isResuming, offset)}
"""

View file

@ -247,7 +247,6 @@ class RecentsPresenter(
.mapNotNull { (key, mcs) ->
val manga = mcs.first().manga
val chapters = mcs.map { ChapterHistory(it.chapter) }
.filterChaptersByScanlators(manga)
extraCount += mcs.size - chapters.size
if (chapters.isEmpty()) return@mapNotNull null
val existingItem = recentItems.takeLast(ENDLESS_LIMIT).find {

View file

@ -32,6 +32,26 @@ AND (
:apply_filter = 0 OR S.name IS NULL
);
getRecents:
SELECT
M.url AS mangaUrl,
M.*,
C.*
FROM mangas AS M
JOIN chapters AS C
ON M._id = C.manga_id
LEFT JOIN scanlators_view AS S
ON C.manga_id = S.manga_id
AND ifnull(C.scanlator, 'N/A') = ifnull(S.name, '/<INVALID>/') -- I assume if it's N/A it shouldn't be filtered
WHERE M.favorite = 1
AND C.date_fetch > M.date_added
AND lower(M.title) LIKE :search
AND (
:apply_filter = 0 OR S.name IS NULL
)
ORDER BY C.date_fetch DESC
LIMIT :limit OFFSET :offset;
getScanlatorsByMangaId:
SELECT scanlator
FROM chapters