pull/2311/head
kunfei 3 years ago
parent a5b77af9f9
commit a1cac7a837
  1. 8
      app/src/main/java/io/legado/app/help/source/BookSourceExtensions.kt
  2. 6
      app/src/main/java/io/legado/app/help/source/RssSourceExtensions.kt

@ -17,12 +17,12 @@ private val mutexMap by lazy { hashMapOf<String, Mutex>() }
private val exploreKindsMap by lazy { ConcurrentHashMap<String, List<ExploreKind>>() }
private val aCache by lazy { ACache.get("explore") }
private fun BookSource.exploreKindsKey(): String {
private fun BookSource.getExploreKindsKey(): String {
return MD5Utils.md5Encode(bookSourceUrl + exploreUrl)
}
suspend fun BookSource.exploreKinds(): List<ExploreKind> {
val exploreKindsKey = exploreKindsKey()
val exploreKindsKey = getExploreKindsKey()
exploreKindsMap[exploreKindsKey]?.let { return it }
val exploreUrl = exploreUrl
if (exploreUrl.isNullOrBlank()) {
@ -30,7 +30,7 @@ suspend fun BookSource.exploreKinds(): List<ExploreKind> {
}
val mutex = mutexMap[bookSourceUrl] ?: Mutex().apply { mutexMap[bookSourceUrl] = this }
mutex.withLock {
exploreKindsMap[exploreKindsKey()]?.let { return it }
exploreKindsMap[exploreKindsKey]?.let { return it }
val kinds = arrayListOf<ExploreKind>()
var ruleStr: String = exploreUrl
withContext(Dispatchers.IO) {
@ -72,6 +72,6 @@ suspend fun BookSource.exploreKinds(): List<ExploreKind> {
suspend fun BookSource.clearExploreKindsCache() {
withContext(Dispatchers.IO) {
aCache.remove(bookSourceUrl)
exploreKindsMap.remove(exploreKindsKey())
exploreKindsMap.remove(getExploreKindsKey())
}
}

@ -8,13 +8,13 @@ import kotlinx.coroutines.withContext
private val aCache by lazy { ACache.get("rssSortUrl") }
private fun RssSource.sortUrlsKey(): String {
private fun RssSource.getSortUrlsKey(): String {
return MD5Utils.md5Encode(sourceUrl + sortUrl)
}
suspend fun RssSource.sortUrls(): List<Pair<String, String>> =
arrayListOf<Pair<String, String>>().apply {
val sortUrlsKey = sortUrlsKey()
val sortUrlsKey = getSortUrlsKey()
withContext(Dispatchers.IO) {
kotlin.runCatching {
var a = sortUrl
@ -46,6 +46,6 @@ suspend fun RssSource.sortUrls(): List<Pair<String, String>> =
suspend fun RssSource.removeSortCache() {
withContext(Dispatchers.IO) {
aCache.remove(sortUrlsKey())
aCache.remove(getSortUrlsKey())
}
}
Loading…
Cancel
Save