mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
chore(recents): Use sql query to filter scanlators pt.2
This commit is contained in:
parent
7926590c22
commit
a2a0a7e79e
5 changed files with 113 additions and 38 deletions
|
@ -40,6 +40,7 @@ fun limitAndOffset(endless: Boolean, isResuming: Boolean, offset: Int): String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Migrate to SQLDelight
|
||||||
/**
|
/**
|
||||||
* Query to get the recently read chapters of manga from the library up to a date.
|
* Query to get the recently read chapters of manga from the library up to a date.
|
||||||
* The max_last_read table contains the most recent chapters grouped by manga
|
* The max_last_read table contains the most recent chapters grouped by manga
|
||||||
|
@ -52,18 +53,27 @@ fun getRecentHistoryUngrouped(
|
||||||
isResuming: Boolean,
|
isResuming: Boolean,
|
||||||
) =
|
) =
|
||||||
"""
|
"""
|
||||||
SELECT ${Manga.TABLE}.${Manga.COL_URL} as mangaUrl, ${Manga.TABLE}.*, ${Chapter.TABLE}.*, ${History.TABLE}.*
|
SELECT
|
||||||
FROM ${Manga.TABLE}
|
M.url AS mangaUrl,
|
||||||
JOIN ${Chapter.TABLE}
|
M.*,
|
||||||
ON ${Manga.TABLE}.${Manga.COL_ID} = ${Chapter.TABLE}.${Chapter.COL_MANGA_ID}
|
C.*,
|
||||||
JOIN ${History.TABLE}
|
H.*
|
||||||
ON ${Chapter.TABLE}.${Chapter.COL_ID} = ${History.TABLE}.${History.COL_CHAPTER_ID}
|
FROM mangas AS M
|
||||||
AND ${History.TABLE}.${History.COL_LAST_READ} > 0
|
JOIN chapters AS C
|
||||||
AND lower(${Manga.TABLE}.${Manga.COL_TITLE}) LIKE '%$search%'
|
ON M._id = C.manga_id
|
||||||
ORDER BY ${History.TABLE}.${History.COL_LAST_READ} DESC
|
JOIN history AS H
|
||||||
|
ON C._id = H.history_chapter_id
|
||||||
|
AND H.history_last_read > 0
|
||||||
|
LEFT JOIN scanlators_view AS S
|
||||||
|
ON C.manga_id = S.manga_id
|
||||||
|
AND ifnull(C.scanlator, 'N/A') = ifnull(S.name, '/<INVALID>/')
|
||||||
|
WHERE lower(M.title) LIKE '%$search%'
|
||||||
|
AND S.name IS NULL
|
||||||
|
ORDER BY H.history_last_read DESC
|
||||||
${limitAndOffset(true, isResuming, offset)}
|
${limitAndOffset(true, isResuming, offset)}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
// TODO: Migrate to SQLDelight
|
||||||
/**
|
/**
|
||||||
* Query to get the recently read chapters of manga from the library up to a date.
|
* Query to get the recently read chapters of manga from the library up to a date.
|
||||||
* The max_last_read table contains the most recent chapters grouped by manga
|
* The max_last_read table contains the most recent chapters grouped by manga
|
||||||
|
@ -76,22 +86,34 @@ fun getRecentMangasLimitQuery(
|
||||||
isResuming: Boolean,
|
isResuming: Boolean,
|
||||||
) =
|
) =
|
||||||
"""
|
"""
|
||||||
SELECT ${Manga.TABLE}.${Manga.COL_URL} as mangaUrl, ${Manga.TABLE}.*, ${Chapter.TABLE}.*, ${History.TABLE}.*
|
SELECT
|
||||||
FROM ${Manga.TABLE}
|
M.url AS mangaUrl,
|
||||||
JOIN ${Chapter.TABLE}
|
M.*,
|
||||||
ON ${Manga.TABLE}.${Manga.COL_ID} = ${Chapter.TABLE}.${Chapter.COL_MANGA_ID}
|
C.*,
|
||||||
JOIN ${History.TABLE}
|
H.*
|
||||||
ON ${Chapter.TABLE}.${Chapter.COL_ID} = ${History.TABLE}.${History.COL_CHAPTER_ID}
|
FROM mangas AS M
|
||||||
|
JOIN chapters AS C
|
||||||
|
ON M._id = C.manga_id
|
||||||
|
JOIN history AS H
|
||||||
|
ON C._id = H.history_chapter_id
|
||||||
JOIN (
|
JOIN (
|
||||||
SELECT ${Chapter.TABLE}.${Chapter.COL_MANGA_ID},${Chapter.TABLE}.${Chapter.COL_ID} as ${History.COL_CHAPTER_ID}, MAX(${History.TABLE}.${History.COL_LAST_READ}) as ${History.COL_LAST_READ}
|
SELECT
|
||||||
FROM ${Chapter.TABLE} JOIN ${History.TABLE}
|
C2.manga_id AS manga_id,
|
||||||
ON ${Chapter.TABLE}.${Chapter.COL_ID} = ${History.TABLE}.${History.COL_CHAPTER_ID}
|
C2._id AS history_chapter_id,
|
||||||
GROUP BY ${Chapter.TABLE}.${Chapter.COL_MANGA_ID}) AS max_last_read
|
MAX(H2.history_last_read) AS history_last_read
|
||||||
ON ${Chapter.TABLE}.${Chapter.COL_MANGA_ID} = max_last_read.${Chapter.COL_MANGA_ID}
|
FROM chapters AS C2 JOIN history AS H2
|
||||||
AND max_last_read.${History.COL_CHAPTER_ID} = ${History.TABLE}.${History.COL_CHAPTER_ID}
|
ON C2._id = H2.history_chapter_id
|
||||||
AND max_last_read.${History.COL_LAST_READ} > 0
|
GROUP BY C2.manga_id
|
||||||
AND lower(${Manga.TABLE}.${Manga.COL_TITLE}) LIKE '%$search%'
|
) AS max_last_read
|
||||||
ORDER BY max_last_read.${History.COL_LAST_READ} DESC
|
ON C.manga_id = max_last_read.manga_id
|
||||||
|
AND max_last_read.history_chapter_id = H.history_chapter_id
|
||||||
|
AND max_last_read.history_last_read > 0
|
||||||
|
LEFT JOIN scanlators_view AS S
|
||||||
|
ON C.manga_id = S.manga_id
|
||||||
|
AND ifnull(C.scanlator, 'N/A') = ifnull(S.name, '/<INVALID>/')
|
||||||
|
WHERE lower(M.title) LIKE '%$search%'
|
||||||
|
AND S.name IS NULL
|
||||||
|
ORDER BY max_last_read.history_last_read DESC
|
||||||
${limitAndOffset(true, isResuming, offset)}
|
${limitAndOffset(true, isResuming, offset)}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@ import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.source.SourceManager
|
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.ChapterFilter.Companion.filterChaptersByScanlators
|
|
||||||
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.executeOnIO
|
||||||
import eu.kanade.tachiyomi.util.system.launchIO
|
import eu.kanade.tachiyomi.util.system.launchIO
|
||||||
|
@ -205,7 +204,7 @@ class RecentsPresenter(
|
||||||
val manga = mchs.first().manga
|
val manga = mchs.first().manga
|
||||||
val chapters = mchs.map { mch ->
|
val chapters = mchs.map { mch ->
|
||||||
ChapterHistory(mch.chapter, mch.history)
|
ChapterHistory(mch.chapter, mch.history)
|
||||||
}.filterChaptersByScanlators(manga)
|
}
|
||||||
extraCount += mchs.size - chapters.size
|
extraCount += mchs.size - chapters.size
|
||||||
if (chapters.isEmpty()) return@mapNotNull null
|
if (chapters.isEmpty()) return@mapNotNull null
|
||||||
val lastAmount = if (groupChaptersHistory == GroupType.ByDay) {
|
val lastAmount = if (groupChaptersHistory == GroupType.ByDay) {
|
||||||
|
|
|
@ -81,15 +81,4 @@ class ChapterFilter(val preferences: PreferencesHelper = Injekt.get(), val downl
|
||||||
|
|
||||||
return filteredChapters
|
return filteredChapters
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
|
||||||
/** filters chapters for scanlators */
|
|
||||||
@Deprecated("Filter it from SQL instead if possible")
|
|
||||||
fun <T : Chapter> List<T>.filterChaptersByScanlators(manga: Manga): List<T> {
|
|
||||||
return manga.filtered_scanlators?.let { filteredScanlatorString ->
|
|
||||||
val filteredScanlators = ChapterUtil.getScanlators(filteredScanlatorString)
|
|
||||||
filter { ChapterUtil.getScanlators(it.scanlator).none { group -> filteredScanlators.contains(group) } }
|
|
||||||
} ?: this
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import eu.kanade.tachiyomi.data.download.DownloadManager
|
||||||
import eu.kanade.tachiyomi.source.Source
|
import eu.kanade.tachiyomi.source.Source
|
||||||
import eu.kanade.tachiyomi.source.model.SChapter
|
import eu.kanade.tachiyomi.source.model.SChapter
|
||||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||||
import eu.kanade.tachiyomi.util.chapter.ChapterFilter.Companion.filterChaptersByScanlators
|
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
@ -203,6 +202,17 @@ suspend fun syncChaptersWithSource(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun List<Chapter>.filterChaptersByScanlators(manga: Manga): List<Chapter> {
|
||||||
|
if (manga.filtered_scanlators == null) return this
|
||||||
|
|
||||||
|
return this.filter { chapter ->
|
||||||
|
ChapterUtil.getScanlators(chapter.scanlator)
|
||||||
|
.none { group ->
|
||||||
|
ChapterUtil.getScanlators(manga.filtered_scanlators).contains(group)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// checks if the chapter in db needs updated
|
// checks if the chapter in db needs updated
|
||||||
private fun shouldUpdateDbChapter(dbChapter: Chapter, sourceChapter: Chapter): Boolean {
|
private fun shouldUpdateDbChapter(dbChapter: Chapter, sourceChapter: Chapter): Boolean {
|
||||||
return dbChapter.scanlator != sourceChapter.scanlator ||
|
return dbChapter.scanlator != sourceChapter.scanlator ||
|
||||||
|
|
|
@ -52,6 +52,61 @@ AND (
|
||||||
ORDER BY C.date_fetch DESC
|
ORDER BY C.date_fetch DESC
|
||||||
LIMIT :limit OFFSET :offset;
|
LIMIT :limit OFFSET :offset;
|
||||||
|
|
||||||
|
getRecentsUngrouped:
|
||||||
|
SELECT
|
||||||
|
M.url AS mangaUrl,
|
||||||
|
M.*,
|
||||||
|
C.*,
|
||||||
|
H.*
|
||||||
|
FROM mangas AS M
|
||||||
|
JOIN chapters AS C
|
||||||
|
ON M._id = C.manga_id
|
||||||
|
JOIN history AS H
|
||||||
|
ON C._id = H.history_chapter_id
|
||||||
|
AND H.history_last_read > 0
|
||||||
|
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 lower(M.title) LIKE :search
|
||||||
|
AND (
|
||||||
|
:apply_filter = 0 OR S.name IS NULL
|
||||||
|
)
|
||||||
|
ORDER BY H.history_last_read DESC
|
||||||
|
LIMIT :limit OFFSET :offset;
|
||||||
|
|
||||||
|
getRecentsBySeries:
|
||||||
|
SELECT
|
||||||
|
M.url AS mangaUrl,
|
||||||
|
M.*,
|
||||||
|
C.*,
|
||||||
|
H.*
|
||||||
|
FROM mangas AS M
|
||||||
|
JOIN chapters AS C
|
||||||
|
ON M._id = C.manga_id
|
||||||
|
JOIN history AS H
|
||||||
|
ON C._id = H.history_chapter_id
|
||||||
|
JOIN (
|
||||||
|
SELECT
|
||||||
|
C2.manga_id AS manga_id,
|
||||||
|
C2._id AS history_chapter_id,
|
||||||
|
MAX(H2.history_last_read) AS history_last_read
|
||||||
|
FROM chapters AS C2 JOIN history AS H2
|
||||||
|
ON C2._id = H2.history_chapter_id
|
||||||
|
GROUP BY C2.manga_id
|
||||||
|
) AS max_last_read
|
||||||
|
ON C.manga_id = max_last_read.manga_id
|
||||||
|
AND max_last_read.history_chapter_id = H.history_chapter_id
|
||||||
|
AND max_last_read.history_last_read > 0
|
||||||
|
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 lower(M.title) LIKE :search
|
||||||
|
AND (
|
||||||
|
:apply_filter = 0 OR S.name IS NULL
|
||||||
|
)
|
||||||
|
ORDER BY max_last_read.history_last_read DESC
|
||||||
|
LIMIT :limit OFFSET :offset;
|
||||||
|
|
||||||
getScanlatorsByMangaId:
|
getScanlatorsByMangaId:
|
||||||
SELECT scanlator
|
SELECT scanlator
|
||||||
FROM chapters
|
FROM chapters
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue