优化
This commit is contained in:
@@ -17,12 +17,12 @@ private val mutexMap by lazy { hashMapOf<String, Mutex>() }
|
|||||||
private val exploreKindsMap by lazy { ConcurrentHashMap<String, List<ExploreKind>>() }
|
private val exploreKindsMap by lazy { ConcurrentHashMap<String, List<ExploreKind>>() }
|
||||||
private val aCache by lazy { ACache.get("explore") }
|
private val aCache by lazy { ACache.get("explore") }
|
||||||
|
|
||||||
private fun BookSource.exploreKindsKey(): String {
|
private fun BookSource.getExploreKindsKey(): String {
|
||||||
return MD5Utils.md5Encode(bookSourceUrl + exploreUrl)
|
return MD5Utils.md5Encode(bookSourceUrl + exploreUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun BookSource.exploreKinds(): List<ExploreKind> {
|
suspend fun BookSource.exploreKinds(): List<ExploreKind> {
|
||||||
val exploreKindsKey = exploreKindsKey()
|
val exploreKindsKey = getExploreKindsKey()
|
||||||
exploreKindsMap[exploreKindsKey]?.let { return it }
|
exploreKindsMap[exploreKindsKey]?.let { return it }
|
||||||
val exploreUrl = exploreUrl
|
val exploreUrl = exploreUrl
|
||||||
if (exploreUrl.isNullOrBlank()) {
|
if (exploreUrl.isNullOrBlank()) {
|
||||||
@@ -30,7 +30,7 @@ suspend fun BookSource.exploreKinds(): List<ExploreKind> {
|
|||||||
}
|
}
|
||||||
val mutex = mutexMap[bookSourceUrl] ?: Mutex().apply { mutexMap[bookSourceUrl] = this }
|
val mutex = mutexMap[bookSourceUrl] ?: Mutex().apply { mutexMap[bookSourceUrl] = this }
|
||||||
mutex.withLock {
|
mutex.withLock {
|
||||||
exploreKindsMap[exploreKindsKey()]?.let { return it }
|
exploreKindsMap[exploreKindsKey]?.let { return it }
|
||||||
val kinds = arrayListOf<ExploreKind>()
|
val kinds = arrayListOf<ExploreKind>()
|
||||||
var ruleStr: String = exploreUrl
|
var ruleStr: String = exploreUrl
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
@@ -72,6 +72,6 @@ suspend fun BookSource.exploreKinds(): List<ExploreKind> {
|
|||||||
suspend fun BookSource.clearExploreKindsCache() {
|
suspend fun BookSource.clearExploreKindsCache() {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
aCache.remove(bookSourceUrl)
|
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 val aCache by lazy { ACache.get("rssSortUrl") }
|
||||||
|
|
||||||
private fun RssSource.sortUrlsKey(): String {
|
private fun RssSource.getSortUrlsKey(): String {
|
||||||
return MD5Utils.md5Encode(sourceUrl + sortUrl)
|
return MD5Utils.md5Encode(sourceUrl + sortUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun RssSource.sortUrls(): List<Pair<String, String>> =
|
suspend fun RssSource.sortUrls(): List<Pair<String, String>> =
|
||||||
arrayListOf<Pair<String, String>>().apply {
|
arrayListOf<Pair<String, String>>().apply {
|
||||||
val sortUrlsKey = sortUrlsKey()
|
val sortUrlsKey = getSortUrlsKey()
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
kotlin.runCatching {
|
kotlin.runCatching {
|
||||||
var a = sortUrl
|
var a = sortUrl
|
||||||
@@ -46,6 +46,6 @@ suspend fun RssSource.sortUrls(): List<Pair<String, String>> =
|
|||||||
|
|
||||||
suspend fun RssSource.removeSortCache() {
|
suspend fun RssSource.removeSortCache() {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
aCache.remove(sortUrlsKey())
|
aCache.remove(getSortUrlsKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user