mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-13 04:28:55 +01:00
More optimizations to library search
This commit is contained in:
@@ -123,4 +123,30 @@ interface MangaQueries : DbProvider {
|
||||
""".trimIndent())
|
||||
.build())
|
||||
.prepare()
|
||||
|
||||
fun getFavoriteMangaWithMetadata() = db.get()
|
||||
.listOfObjects(Manga::class.java)
|
||||
.withQuery(RawQuery.builder()
|
||||
.query("""
|
||||
SELECT ${MangaTable.TABLE}.* FROM ${MangaTable.TABLE}
|
||||
INNER JOIN ${SearchMetadataTable.TABLE}
|
||||
ON ${MangaTable.TABLE}.${MangaTable.COL_ID} = ${SearchMetadataTable.TABLE}.${SearchMetadataTable.COL_MANGA_ID}
|
||||
WHERE ${MangaTable.TABLE}.${MangaTable.COL_FAVORITE} = 1
|
||||
ORDER BY ${MangaTable.TABLE}.${MangaTable.COL_ID}
|
||||
""".trimIndent())
|
||||
.build())
|
||||
.prepare()
|
||||
|
||||
fun getIdsOfFavoriteMangaWithMetadata() = db.get()
|
||||
.cursor()
|
||||
.withQuery(RawQuery.builder()
|
||||
.query("""
|
||||
SELECT ${MangaTable.TABLE}.${MangaTable.COL_ID} FROM ${MangaTable.TABLE}
|
||||
INNER JOIN ${SearchMetadataTable.TABLE}
|
||||
ON ${MangaTable.TABLE}.${MangaTable.COL_ID} = ${SearchMetadataTable.TABLE}.${SearchMetadataTable.COL_MANGA_ID}
|
||||
WHERE ${MangaTable.TABLE}.${MangaTable.COL_FAVORITE} = 1
|
||||
ORDER BY ${MangaTable.TABLE}.${MangaTable.COL_ID}
|
||||
""".trimIndent())
|
||||
.build())
|
||||
.prepare()
|
||||
}
|
||||
|
||||
@@ -4,9 +4,11 @@ import com.pushtorefresh.storio.sqlite.queries.RawQuery
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.database.tables.MangaTable
|
||||
import exh.isLewdSource
|
||||
import exh.metadata.sql.tables.SearchMetadataTable
|
||||
import exh.search.SearchEngine
|
||||
import exh.util.await
|
||||
import exh.util.cancellable
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.asFlow
|
||||
@@ -78,7 +80,20 @@ class LibraryCategoryAdapter(val view: LibraryCategoryView) :
|
||||
.args(*sqlQuery.second.toTypedArray())
|
||||
.build())
|
||||
|
||||
val mangaWithMetadata = db.getMangaWithMetadata().executeAsBlocking()
|
||||
ensureActive() // Fail early when cancelled
|
||||
|
||||
val mangaWithMetaIdsQuery = db.getIdsOfFavoriteMangaWithMetadata().await()
|
||||
val mangaWithMetaIds = LongArray(mangaWithMetaIdsQuery.count)
|
||||
if(mangaWithMetaIds.isNotEmpty()) {
|
||||
val mangaIdCol = mangaWithMetaIdsQuery.getColumnIndex(MangaTable.COL_ID)
|
||||
mangaWithMetaIdsQuery.moveToFirst()
|
||||
while (!mangaWithMetaIdsQuery.isAfterLast) {
|
||||
ensureActive() // Fail early when cancelled
|
||||
|
||||
mangaWithMetaIds[mangaWithMetaIdsQuery.position] = mangaWithMetaIdsQuery.getLong(mangaIdCol)
|
||||
mangaWithMetaIdsQuery.moveToNext()
|
||||
}
|
||||
}
|
||||
|
||||
ensureActive() // Fail early when cancelled
|
||||
|
||||
@@ -102,7 +117,7 @@ class LibraryCategoryAdapter(val view: LibraryCategoryView) :
|
||||
val mangaId = item.manga.id ?: -1
|
||||
if(convertedResult.binarySearch(mangaId) < 0) {
|
||||
// Check if this manga even has metadata
|
||||
if(mangaWithMetadata.binarySearchBy(mangaId) { it.id } < 0) {
|
||||
if(mangaWithMetaIds.binarySearch(mangaId) < 0) {
|
||||
// No meta? Filter using title
|
||||
item.filter(savedSearchText)
|
||||
} else false
|
||||
|
||||
@@ -131,7 +131,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
||||
subscriptions += controller.searchRelay
|
||||
.doOnNext { adapter.searchText = it }
|
||||
.skip(1)
|
||||
.debounce(250, TimeUnit.MILLISECONDS)
|
||||
.debounce(500, TimeUnit.MILLISECONDS)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe {
|
||||
// EXH -->
|
||||
|
||||
@@ -277,8 +277,8 @@ class SettingsEhController : SettingsController() {
|
||||
"The updater last ran ${Humanize.naturalTime(Date(stats.startTime))}, and checked ${stats.updateCount} out of the ${stats.possibleUpdates} galleries that were ready for checking."
|
||||
} else "The updater has not ran yet."
|
||||
|
||||
val allMeta = db.getMangaWithMetadata().await().filter {
|
||||
it.favorite && (it.source == EH_SOURCE_ID || it.source == EXH_SOURCE_ID)
|
||||
val allMeta = db.getFavoriteMangaWithMetadata().await().filter {
|
||||
it.source == EH_SOURCE_ID || it.source == EXH_SOURCE_ID
|
||||
}.mapNotNull {
|
||||
db.getFlatMetadataForManga(it.id!!).await()?.raise<EHentaiSearchMetadata>()
|
||||
}.toList()
|
||||
|
||||
Reference in New Issue
Block a user