mirror of
https://github.com/null2264/yokai.git
synced 2025-06-20 18:24:42 +00:00
fix(recents): Find unread from SQL instead of code
This commit is contained in:
parent
263603616e
commit
e5b8ed9e9d
6 changed files with 34 additions and 7 deletions
|
@ -485,17 +485,16 @@ class RecentsPresenter(
|
|||
|
||||
private suspend fun getNextChapter(manga: Manga): Chapter? {
|
||||
val mangaId = manga.id ?: return null
|
||||
val chapters = getChapter.awaitAll(mangaId, true)
|
||||
return ChapterSort(manga, chapterFilter, preferences).getNextUnreadChapter(chapters, false)
|
||||
val chapters = getChapter.awaitUnread(mangaId, true)
|
||||
return ChapterSort(manga, chapterFilter, preferences).getNextChapter(chapters, false)
|
||||
}
|
||||
|
||||
private suspend fun getFirstUpdatedChapter(manga: Manga, chapter: Chapter): Chapter? {
|
||||
val mangaId = manga.id ?: return null
|
||||
val chapters = getChapter.awaitAll(mangaId, true)
|
||||
return chapters
|
||||
.sortedWith(ChapterSort(manga, chapterFilter, preferences).sortComparator(true)).find {
|
||||
!it.read && abs(it.date_fetch - chapter.date_fetch) <= TimeUnit.HOURS.toMillis(12)
|
||||
}
|
||||
val chapters = getChapter.awaitUnread(mangaId, true)
|
||||
return chapters.sortedWith(ChapterSort(manga, chapterFilter, preferences).sortComparator(true)).find {
|
||||
abs(it.date_fetch - chapter.date_fetch) <= TimeUnit.HOURS.toMillis(12)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
|
|
@ -30,6 +30,14 @@ class ChapterSort(val manga: Manga, val chapterFilter: ChapterFilter = Injekt.ge
|
|||
return chapters.sortedWith(sortComparator())
|
||||
}
|
||||
|
||||
fun <T : Chapter> getNextChapter(rawChapters: List<T>, andFiltered: Boolean = true): T? {
|
||||
val chapters = when {
|
||||
andFiltered -> chapterFilter.filterChapters(rawChapters, manga)
|
||||
else -> rawChapters
|
||||
}
|
||||
return chapters.sortedWith(sortComparator(true)).firstOrNull()
|
||||
}
|
||||
|
||||
fun <T : Chapter> getNextUnreadChapter(rawChapters: List<T>, andFiltered: Boolean = true): T? {
|
||||
val chapters = when {
|
||||
andFiltered -> chapterFilter.filterChapters(rawChapters, manga)
|
||||
|
|
|
@ -43,6 +43,11 @@ class ChapterRepositoryImpl(private val handler: DatabaseHandler) : ChapterRepos
|
|||
chaptersQueries.getChaptersByUrlAndMangaId(url, mangaId, filterScanlators.toInt().toLong(), Chapter::mapper)
|
||||
}
|
||||
|
||||
override suspend fun getUnread(mangaId: Long, filterScanlators: Boolean): List<Chapter> =
|
||||
handler.awaitList {
|
||||
chaptersQueries.findUnreadByMangaId(mangaId, filterScanlators.toInt().toLong(), Chapter::mapper)
|
||||
}
|
||||
|
||||
override suspend fun getRecents(filterScanlators: Boolean, search: String, limit: Long, offset: Long): List<MangaChapter> =
|
||||
handler.awaitList { chaptersQueries.getRecents(search, filterScanlators.toInt().toLong(), limit, offset, MangaChapter::mapper) }
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ interface ChapterRepository {
|
|||
|
||||
suspend fun getChaptersByUrlAndMangaId(url: String, mangaId: Long, filterScanlators: Boolean): List<Chapter>
|
||||
suspend fun getChapterByUrlAndMangaId(url: String, mangaId: Long, filterScanlators: Boolean): Chapter?
|
||||
suspend fun getUnread(mangaId: Long, filterScanlators: Boolean): List<Chapter>
|
||||
|
||||
suspend fun getRecents(filterScanlators: Boolean, search: String = "", limit: Long = 25L, offset: Long = 0L): List<MangaChapter>
|
||||
|
||||
|
|
|
@ -11,6 +11,9 @@ class GetChapter(
|
|||
suspend fun awaitAll(manga: Manga, filterScanlators: Boolean? = null) =
|
||||
awaitAll(manga.id!!, filterScanlators ?: (manga.filtered_scanlators?.isNotEmpty() == true))
|
||||
|
||||
suspend fun awaitUnread(mangaId: Long, filterScanlators: Boolean) =
|
||||
chapterRepository.getUnread(mangaId, filterScanlators)
|
||||
|
||||
suspend fun awaitById(id: Long) = chapterRepository.getChapterById(id)
|
||||
|
||||
suspend fun awaitAllByUrl(chapterUrl: String, filterScanlators: Boolean) =
|
||||
|
|
|
@ -58,6 +58,17 @@ AND (
|
|||
:apply_filter = 0 OR S.name IS NULL
|
||||
);
|
||||
|
||||
findUnreadByMangaId:
|
||||
SELECT C.*
|
||||
FROM chapters AS C
|
||||
LEFT JOIN scanlators_view AS S
|
||||
ON C.manga_id = S.manga_id
|
||||
AND C.scanlator = S.name
|
||||
WHERE C.manga_id = :manga_id AND C.read = 0
|
||||
AND (
|
||||
:apply_filter = 0 OR S.name IS NULL
|
||||
);
|
||||
|
||||
getRecents:
|
||||
SELECT
|
||||
M.*,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue