优化
Some checks are pending
Test Build / prepare (push) Waiting to run
Test Build / build (app, release) (push) Blocked by required conditions
Test Build / build (app, releaseA) (push) Blocked by required conditions
Test Build / prerelease (push) Blocked by required conditions
Test Build / lanzou (push) Blocked by required conditions
Test Build / test_Branch (push) Blocked by required conditions
Test Build / telegram (push) Blocked by required conditions

This commit is contained in:
Horis
2025-02-24 17:59:21 +08:00
parent d0e76a6b9c
commit 2d728929dc
6 changed files with 2033 additions and 103 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -32,6 +32,7 @@ import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.BookGroup
import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.BookSourcePart
import io.legado.app.data.entities.Bookmark
import io.legado.app.data.entities.Cache
import io.legado.app.data.entities.Cookie
@@ -64,13 +65,14 @@ val appDb by lazy {
}
@Database(
version = 74,
version = 75,
exportSchema = true,
entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class,
ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class,
RssSource::class, Bookmark::class, RssArticle::class, RssReadRecord::class,
RssStar::class, TxtTocRule::class, ReadRecord::class, HttpTTS::class, Cache::class,
RuleSub::class, DictRule::class, KeyboardAssist::class, Server::class],
views = [BookSourcePart::class],
autoMigrations = [
AutoMigration(from = 43, to = 44),
AutoMigration(from = 44, to = 45),
@@ -103,6 +105,7 @@ val appDb by lazy {
AutoMigration(from = 71, to = 72),
AutoMigration(from = 72, to = 73),
AutoMigration(from = 73, to = 74),
AutoMigration(from = 74, to = 75),
]
)
abstract class AppDatabase : RoomDatabase() {

View File

@@ -20,22 +20,17 @@ import kotlinx.coroutines.flow.map
@Dao
interface BookSourceDao {
@Query(
"""select bookSourceUrl, bookSourceName, bookSourceGroup, customOrder, enabled, enabledExplore,
trim(loginUrl) <> '' hasLoginUrl, lastUpdateTime, respondTime, weight, trim(exploreUrl) <> '' hasExploreUrl
from book_sources order by customOrder asc"""
)
@Query("select * from book_sources_part order by customOrder asc")
fun flowAll(): Flow<List<BookSourcePart>>
@Query(
"""select bookSourceUrl, bookSourceName, bookSourceGroup, customOrder, enabled, enabledExplore,
trim(loginUrl) <> '' hasLoginUrl, lastUpdateTime, respondTime, weight, trim(exploreUrl) <> '' hasExploreUrl
from book_sources
where bookSourceName like '%' || :searchKey || '%'
or bookSourceGroup like '%' || :searchKey || '%'
or bookSourceUrl like '%' || :searchKey || '%'
or bookSourceComment like '%' || :searchKey || '%'
order by customOrder asc"""
"""select bp.*
from book_sources b join book_sources_part bp on b.bookSourceUrl = bp.bookSourceUrl
where b.bookSourceName like '%' || :searchKey || '%'
or b.bookSourceGroup like '%' || :searchKey || '%'
or b.bookSourceUrl like '%' || :searchKey || '%'
or b.bookSourceComment like '%' || :searchKey || '%'
order by b.customOrder asc"""
)
fun flowSearch(searchKey: String): Flow<List<BookSourcePart>>
@@ -50,22 +45,19 @@ interface BookSourceDao {
fun search(searchKey: String): List<BookSource>
@Query(
"""select bookSourceUrl, bookSourceName, bookSourceGroup, customOrder, enabled, enabledExplore,
trim(loginUrl) <> '' hasLoginUrl, lastUpdateTime, respondTime, weight, trim(exploreUrl) <> '' hasExploreUrl
from book_sources
where enabled = 1 and
(bookSourceName like '%' || :searchKey || '%'
or bookSourceGroup like '%' || :searchKey || '%'
or bookSourceUrl like '%' || :searchKey || '%'
or bookSourceComment like '%' || :searchKey || '%')
order by customOrder asc"""
"""select bp.*
from book_sources b join book_sources_part bp on b.bookSourceUrl = bp.bookSourceUrl
where b.enabled = 1
and (b.bookSourceName like '%' || :searchKey || '%'
or b.bookSourceGroup like '%' || :searchKey || '%'
or b.bookSourceUrl like '%' || :searchKey || '%'
or b.bookSourceComment like '%' || :searchKey || '%')
order by b.customOrder asc"""
)
fun flowSearchEnabled(searchKey: String): Flow<List<BookSourcePart>>
@Query(
"""select bookSourceUrl, bookSourceName, bookSourceGroup, customOrder, enabled, enabledExplore,
trim(loginUrl) <> '' hasLoginUrl, lastUpdateTime, respondTime, weight, trim(exploreUrl) <> '' hasExploreUrl
from book_sources
"""select * from book_sources_part
where bookSourceGroup = :searchKey
or bookSourceGroup like :searchKey || ',%'
or bookSourceGroup like '%,' || :searchKey
@@ -84,63 +76,38 @@ interface BookSourceDao {
)
fun groupSearch(searchKey: String): List<BookSource>
@Query(
"""select bookSourceUrl, bookSourceName, bookSourceGroup, customOrder, enabled, enabledExplore,
trim(loginUrl) <> '' hasLoginUrl, lastUpdateTime, respondTime, weight, trim(exploreUrl) <> '' hasExploreUrl
from book_sources where enabled = 1 order by customOrder asc"""
)
@Query("select * from book_sources_part where enabled = 1 order by customOrder asc")
fun flowEnabled(): Flow<List<BookSourcePart>>
@Query(
"""select bookSourceUrl, bookSourceName, bookSourceGroup, customOrder, enabled, enabledExplore,
trim(loginUrl) <> '' hasLoginUrl, lastUpdateTime, respondTime, weight, trim(exploreUrl) <> '' hasExploreUrl
from book_sources where enabled = 0 order by customOrder asc"""
)
@Query("select * from book_sources_part where enabled = 0 order by customOrder asc")
fun flowDisabled(): Flow<List<BookSourcePart>>
@Query(
"""select bookSourceUrl, bookSourceName, bookSourceGroup, customOrder, enabled, enabledExplore,
trim(loginUrl) <> '' hasLoginUrl, lastUpdateTime, respondTime, weight, trim(exploreUrl) <> '' hasExploreUrl
from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' order by customOrder asc"""
"""select * from book_sources_part
where enabledExplore = 1 and hasExploreUrl = 1 order by customOrder asc"""
)
fun flowExplore(): Flow<List<BookSourcePart>>
@Query(
"""select bookSourceUrl, bookSourceName, bookSourceGroup, customOrder, enabled, enabledExplore,
trim(loginUrl) <> '' hasLoginUrl, lastUpdateTime, respondTime, weight, trim(exploreUrl) <> '' hasExploreUrl
from book_sources where loginUrl is not null and loginUrl != ''
order by customOrder asc"""
)
@Query("select * from book_sources_part where hasLoginUrl = 1 order by customOrder asc")
fun flowLogin(): Flow<List<BookSourcePart>>
@Query(
"""select bookSourceUrl, bookSourceName, bookSourceGroup, customOrder, enabled, enabledExplore,
trim(loginUrl) <> '' hasLoginUrl, lastUpdateTime, respondTime, weight, trim(exploreUrl) <> '' hasExploreUrl
from book_sources where bookSourceGroup is null or bookSourceGroup = '' or bookSourceGroup like '%未分组%'
"""select * from book_sources_part
where bookSourceGroup is null or bookSourceGroup = '' or bookSourceGroup like '%未分组%'
order by customOrder asc"""
)
fun flowNoGroup(): Flow<List<BookSourcePart>>
@Query(
"""select bookSourceUrl, bookSourceName, bookSourceGroup, customOrder, enabled, enabledExplore,
trim(loginUrl) <> '' hasLoginUrl, lastUpdateTime, respondTime, weight, trim(exploreUrl) <> '' hasExploreUrl
from book_sources where enabledExplore = 1 order by customOrder asc"""
)
@Query("select * from book_sources_part where enabledExplore = 1 order by customOrder asc")
fun flowEnabledExplore(): Flow<List<BookSourcePart>>
@Query(
"""select bookSourceUrl, bookSourceName, bookSourceGroup, customOrder, enabled, enabledExplore,
trim(loginUrl) <> '' hasLoginUrl, lastUpdateTime, respondTime, weight, trim(exploreUrl) <> '' hasExploreUrl
from book_sources where enabledExplore = 0 order by customOrder asc"""
)
@Query("select * from book_sources_part where enabledExplore = 0 order by customOrder asc")
fun flowDisabledExplore(): Flow<List<BookSourcePart>>
@Query(
"""select bookSourceUrl, bookSourceName, bookSourceGroup, customOrder, enabled, enabledExplore,
trim(loginUrl) <> '' hasLoginUrl, lastUpdateTime, respondTime, weight, trim(exploreUrl) <> '' hasExploreUrl
from book_sources
"""select * from book_sources_part
where enabledExplore = 1
and trim(exploreUrl) <> ''
and hasExploreUrl = 1
and (bookSourceGroup like '%' || :key || '%'
or bookSourceName like '%' || :key || '%')
order by customOrder asc"""
@@ -148,11 +115,9 @@ interface BookSourceDao {
fun flowExplore(key: String): Flow<List<BookSourcePart>>
@Query(
"""select bookSourceUrl, bookSourceName, bookSourceGroup, customOrder, enabled, enabledExplore,
trim(loginUrl) <> '' hasLoginUrl, lastUpdateTime, respondTime, weight, trim(exploreUrl) <> '' hasExploreUrl
from book_sources
"""select * from book_sources_part
where enabledExplore = 1
and trim(exploreUrl) <> ''
and hasExploreUrl = 1
and (bookSourceGroup = :key
or bookSourceGroup like :key || ',%'
or bookSourceGroup like '%,' || :key
@@ -164,7 +129,10 @@ interface BookSourceDao {
@Query("select distinct bookSourceGroup from book_sources where trim(bookSourceGroup) <> ''")
fun flowGroupsUnProcessed(): Flow<List<String>>
@Query("select distinct bookSourceGroup from book_sources where enabled = 1 and trim(bookSourceGroup) <> ''")
@Query(
"""select distinct bookSourceGroup from book_sources
where enabled = 1 and trim(bookSourceGroup) <> ''"""
)
fun flowEnabledGroupsUnProcessed(): Flow<List<String>>
@Query(
@@ -176,7 +144,10 @@ interface BookSourceDao {
)
fun flowExploreGroupsUnProcessed(): Flow<List<String>>
@Query("select * from book_sources where bookSourceGroup like '%' || :group || '%' order by customOrder asc")
@Query(
"""select * from book_sources
where bookSourceGroup like '%' || :group || '%' order by customOrder asc"""
)
fun getByGroup(group: String): List<BookSource>
@Query(
@@ -191,9 +162,7 @@ interface BookSourceDao {
fun getEnabledByGroup(group: String): List<BookSource>
@Query(
"""select bookSourceUrl, bookSourceName, bookSourceGroup, customOrder, enabled, enabledExplore,
trim(loginUrl) <> '' hasLoginUrl, lastUpdateTime, respondTime, weight, trim(exploreUrl) <> '' hasExploreUrl
from book_sources
"""select * from book_sources_part
where enabled = 1
and (bookSourceGroup = :group
or bookSourceGroup like :group || ',%'
@@ -203,14 +172,24 @@ interface BookSourceDao {
)
fun getEnabledPartByGroup(group: String): List<BookSourcePart>
@Query("select * from book_sources where bookUrlPattern != 'NONE' and bookSourceType = :type order by customOrder asc")
@Query(
"""select * from book_sources
where bookUrlPattern != 'NONE' and bookSourceType = :type order by customOrder asc"""
)
fun getEnabledByType(type: Int): List<BookSource>
@Query("select * from book_sources where enabled = 1 and bookSourceUrl = :baseUrl")
fun getBookSourceAddBook(baseUrl: String): BookSource?
@get:Query("select * from book_sources where enabled = 1 and trim(bookUrlPattern) <> '' and trim(bookUrlPattern) <> 'NONE' order by customOrder")
val hasBookUrlPattern: List<BookSource>
@get:Query(
"""select bp.*
from book_sources b join book_sources_part bp on b.bookSourceUrl = bp.bookSourceUrl
where b.enabled = 1
and trim(b.bookUrlPattern) <> ''
and trim(b.bookUrlPattern) <> 'NONE'
order by b.customOrder"""
)
val hasBookUrlPattern: List<BookSourcePart>
@get:Query("select * from book_sources where bookSourceGroup is null or bookSourceGroup = ''")
val noGroup: List<BookSource>
@@ -218,27 +197,22 @@ interface BookSourceDao {
@get:Query("select * from book_sources order by customOrder asc")
val all: List<BookSource>
@get:Query(
"""select bookSourceUrl, bookSourceName, bookSourceGroup, customOrder, enabled, enabledExplore,
trim(loginUrl) <> '' hasLoginUrl, lastUpdateTime, respondTime, weight, trim(exploreUrl) <> '' hasExploreUrl
from book_sources order by customOrder asc"""
)
@get:Query("select * from book_sources_part order by customOrder asc")
val allPart: List<BookSourcePart>
@get:Query("select * from book_sources where enabled = 1 order by customOrder")
val allEnabled: List<BookSource>
@get:Query(
"""select bookSourceUrl, bookSourceName, bookSourceGroup, customOrder, enabled, enabledExplore,
trim(loginUrl) <> '' hasLoginUrl, lastUpdateTime, respondTime, weight, trim(exploreUrl) <> '' hasExploreUrl
from book_sources where enabled = 1 order by customOrder asc"""
)
@get:Query("select * from book_sources_part where enabled = 1 order by customOrder asc")
val allEnabledPart: List<BookSourcePart>
@get:Query("select * from book_sources where enabled = 0 order by customOrder")
val allDisabled: List<BookSource>
@get:Query("select * from book_sources where bookSourceGroup is null or bookSourceGroup = '' or bookSourceGroup like '%未分组%'")
@get:Query(
"""select * from book_sources
where bookSourceGroup is null or bookSourceGroup = '' or bookSourceGroup like '%未分组%'"""
)
val allNoGroup: List<BookSource>
@get:Query("select * from book_sources where enabledExplore = 1 order by customOrder")
@@ -251,26 +225,28 @@ interface BookSourceDao {
val allLogin: List<BookSource>
@get:Query(
"""select bookSourceUrl, bookSourceName, bookSourceGroup, customOrder, enabled, enabledExplore,
trim(loginUrl) <> '' hasLoginUrl, lastUpdateTime, respondTime, weight, trim(exploreUrl) <> '' hasExploreUrl
from book_sources where enabled = 1 and bookSourceType = 0 order by customOrder"""
"""select bp.*
from book_sources b join book_sources_part bp on b.bookSourceUrl = bp.bookSourceUrl
where b.enabled = 1 and b.bookSourceType = 0 order by b.customOrder"""
)
val allTextEnabledPart: List<BookSourcePart>
@get:Query("select distinct bookSourceGroup from book_sources where trim(bookSourceGroup) <> ''")
@get:Query(
"""select distinct bookSourceGroup from book_sources
where trim(bookSourceGroup) <> ''"""
)
val allGroupsUnProcessed: List<String>
@get:Query("select distinct bookSourceGroup from book_sources where enabled = 1 and trim(bookSourceGroup) <> ''")
@get:Query(
"""select distinct bookSourceGroup from book_sources
where enabled = 1 and trim(bookSourceGroup) <> ''"""
)
val allEnabledGroupsUnProcessed: List<String>
@Query("select * from book_sources where bookSourceUrl = :key")
fun getBookSource(key: String): BookSource?
@Query(
"""select bookSourceUrl, bookSourceName, bookSourceGroup, customOrder, enabled, enabledExplore,
trim(loginUrl) <> '' hasLoginUrl, lastUpdateTime, respondTime, weight, trim(exploreUrl) <> '' hasExploreUrl
from book_sources where bookSourceUrl = :key"""
)
@Query("select * from book_sources_part where bookSourceUrl = :key")
fun getBookSourcePart(key: String): BookSourcePart?
@Query("select count(*) from book_sources")
@@ -324,7 +300,10 @@ interface BookSourceDao {
}
}
@Query("update book_sources set customOrder = :customOrder where bookSourceUrl = :bookSourceUrl")
@Query(
"""update book_sources
set customOrder = :customOrder where bookSourceUrl = :bookSourceUrl"""
)
fun upOrder(bookSourceUrl: String, customOrder: Int)
@Transaction
@@ -338,7 +317,10 @@ interface BookSourceDao {
upOrder(bookSource.bookSourceUrl, bookSource.customOrder)
}
@Query("update book_sources set bookSourceGroup = :bookSourceGroup where bookSourceUrl = :bookSourceUrl")
@Query(
"""update book_sources
set bookSourceGroup = :bookSourceGroup where bookSourceUrl = :bookSourceUrl"""
)
fun upGroup(bookSourceUrl: String, bookSourceGroup: String)
@Transaction

View File

@@ -1,11 +1,19 @@
package io.legado.app.data.entities
import android.text.TextUtils
import androidx.room.DatabaseView
import io.legado.app.constant.AppPattern
import io.legado.app.data.appDb
import io.legado.app.utils.splitNotBlank
@DatabaseView(
"""select bookSourceUrl, bookSourceName, bookSourceGroup, customOrder, enabled, enabledExplore,
(loginUrl is not null and trim(loginUrl) <> '') hasLoginUrl, lastUpdateTime, respondTime, weight,
(exploreUrl is not null and trim(exploreUrl) <> '') hasExploreUrl
from book_sources""",
viewName = "book_sources_part"
)
data class BookSourcePart(
// 地址,包括 http/https
var bookSourceUrl: String = "",

View File

@@ -128,8 +128,9 @@ class AddToBookshelfDialog() : BaseDialogFragment(R.layout.dialog_add_to_bookshe
}
appDb.bookSourceDao.hasBookUrlPattern.forEach { source ->
try {
if (bookUrl.matches(source.bookUrlPattern!!.toRegex())) {
getBookInfo(bookUrl, source)?.let { book ->
val bs = source.getBookSource()!!
if (bookUrl.matches(bs.bookUrlPattern!!.toRegex())) {
getBookInfo(bookUrl, bs)?.let { book ->
return@execute book
}
}

View File

@@ -8,7 +8,7 @@ import io.legado.app.base.BaseViewModel
import io.legado.app.constant.AppLog
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.BookSourcePart
import io.legado.app.exception.NoStackTraceException
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.http.newCallResponseBody
@@ -35,7 +35,7 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
fun addBookByUrl(bookUrls: String) {
var successCount = 0
addBookJob = execute {
val hasBookUrlPattern: List<BookSource> by lazy {
val hasBookUrlPattern: List<BookSourcePart> by lazy {
appDb.bookSourceDao.hasBookUrlPattern
}
val urls = bookUrls.split("\n")
@@ -51,8 +51,9 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
if (source == null) {
for (bookSource in hasBookUrlPattern) {
try {
if (bookUrl.matches(bookSource.bookUrlPattern!!.toRegex())) {
source = bookSource
val bs = bookSource.getBookSource()!!
if (bookUrl.matches(bs.bookUrlPattern!!.toRegex())) {
source = bs
break
}
} catch (_: Exception) {