Workaround for massive thumb requests delay post request for (adding favourite, get torrent list etc.)
Currently okhttp does not support request priority(See https://github.com/square/okhttp/issues/404), and our GalleryDetailScene will launch at most 200 image requests once, which stuffed okhttp async request queue. We need another http client to ensure these plain-text request executed in time
This commit is contained in:
1 parent
14843ddda7
commit
0a9d7c5560
3 files changed
+13
-9
No files matched your search
@@ -215,7 +215,7 @@ class EhApplication : Application(), DefaultLifecycleObserver, ImageLoaderFactor
|
||||
@JvmStatic
|
||||
val ehProxySelector by lazy { EhProxySelector() }
|
||||
|
||||
val nonCacheOkHttpClient by lazy {
|
||||
private fun buildOneOkHttpClient(): OkHttpClient.Builder {
|
||||
val builder = OkHttpClient.Builder()
|
||||
.cookieJar(EhCookieStore)
|
||||
.dns(EhDns)
|
||||
@@ -231,12 +231,16 @@ class EhApplication : Application(), DefaultLifecycleObserver, ImageLoaderFactor
|
||||
builder.sslSocketFactory(EhSSLSocketFactory, trustManager)
|
||||
builder.proxy(Proxy.NO_PROXY)
|
||||
}
|
||||
builder.build()
|
||||
return builder
|
||||
}
|
||||
|
||||
val nonCacheOkHttpClient by lazy {
|
||||
buildOneOkHttpClient().build()
|
||||
}
|
||||
|
||||
// Never use this okhttp client to download large blobs!!!
|
||||
val okHttpClient by lazy {
|
||||
nonCacheOkHttpClient.newBuilder().cache(
|
||||
val plainTextOkHttpClient by lazy {
|
||||
buildOneOkHttpClient().cache(
|
||||
Cache(
|
||||
application.cacheDir.toOkioPath() / "http_cache",
|
||||
20L * 1024L * 1024L,
|
||||
|
||||
@@ -67,7 +67,7 @@ import org.jsoup.Jsoup
|
||||
import java.io.File
|
||||
import kotlin.math.ceil
|
||||
|
||||
private val okHttpClient = EhApplication.okHttpClient
|
||||
private val okHttpClient = EhApplication.plainTextOkHttpClient
|
||||
private val MEDIA_TYPE_JSON: MediaType = "application/json; charset=utf-8".toMediaType()
|
||||
private const val TAG = "EhEngine"
|
||||
private const val MAX_REQUEST_SIZE = 25
|
||||
|
||||
@@ -20,7 +20,7 @@ import android.util.Log
|
||||
import androidx.annotation.IntDef
|
||||
import androidx.collection.LongSparseArray
|
||||
import androidx.collection.set
|
||||
import com.hippo.ehviewer.EhApplication.Companion.okHttpClient
|
||||
import com.hippo.ehviewer.EhApplication.Companion.plainTextOkHttpClient
|
||||
import com.hippo.ehviewer.GetText
|
||||
import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.Settings
|
||||
@@ -362,7 +362,7 @@ class SpiderQueen private constructor(val galleryInfo: GalleryInfo) : CoroutineS
|
||||
), referer
|
||||
).build()
|
||||
return runSuspendCatching {
|
||||
okHttpClient.newCall(request).executeAsync().use { response ->
|
||||
plainTextOkHttpClient.newCall(request).executeAsync().use { response ->
|
||||
val body = response.body.string()
|
||||
val pages = parsePages(body)
|
||||
val spiderInfo = SpiderInfo(galleryInfo.gid, pages)
|
||||
@@ -383,7 +383,7 @@ class SpiderQueen private constructor(val galleryInfo: GalleryInfo) : CoroutineS
|
||||
val referer = referer
|
||||
val request = EhRequestBuilder(url, referer).build()
|
||||
try {
|
||||
okHttpClient.newCall(request).execute().use { response ->
|
||||
plainTextOkHttpClient.newCall(request).execute().use { response ->
|
||||
val body = response.body.string()
|
||||
val list = GalleryMultiPageViewerPTokenParser.parse(body)
|
||||
for (i in list.indices) {
|
||||
@@ -416,7 +416,7 @@ class SpiderQueen private constructor(val galleryInfo: GalleryInfo) : CoroutineS
|
||||
val referer = referer
|
||||
val request = EhRequestBuilder(url, referer).build()
|
||||
try {
|
||||
okHttpClient.newCall(request).execute().use { response ->
|
||||
plainTextOkHttpClient.newCall(request).execute().use { response ->
|
||||
val body = response.body.string()
|
||||
readPreviews(body, previewIndex, spiderInfo)
|
||||
return spiderInfo.pTokenMap[index]
|
||||
|
||||
Reference in new issue
Block a user