-
Notifications
You must be signed in to change notification settings - Fork 790
Manhastro: Fix content loading #10155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
private fun loadFromCache(): ResponseWrapper<List<MangaDto>>? { | ||
val jsonValue = preferences.getString(STORAGE_PREF, null) ?: return null | ||
val storage = jsonValue.parseAs<Storage>() | ||
return storage.takeIf { !it.isExpired() }?.mangas | ||
} | ||
|
||
private fun upsetCookie(cookie: Cookie) { | ||
preferences.edit() | ||
.putString(COOKIE_STORAGE_PREF, json.encodeToString(cookie)) | ||
.apply() | ||
private fun loadFromNetwork(): ResponseWrapper<List<MangaDto>> { | ||
return client.newCall(GET("$apiUrl/dados")) | ||
.execute() | ||
.parseAs<ResponseWrapper<List<MangaDto>>>() | ||
.also { | ||
Storage().apply { | ||
update(it) | ||
preferences.edit() | ||
.putString(STORAGE_PREF, json.encodeToString(this)) | ||
.apply() | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow these steps to use a disk cache instead of persisting 10MB+ of data into SharedPreferences:
- Tweak
this.client
's interceptors:
extensions-source/lib-multisrc/kemono/src/eu/kanade/tachiyomi/multisrc/kemono/Kemono.kt
Lines 51 to 54 in 92ab8f0
.apply { val index = networkInterceptors().indexOfFirst { it is BrotliInterceptor } if (index >= 0) interceptors().add(networkInterceptors().removeAt(index)) }
extensions-source/lib-multisrc/kemono/build.gradle.kts
Lines 7 to 9 in 92ab8f0
dependencies { compileOnly("com.squareup.okhttp3:okhttp-brotli:5.0.0-alpha.11") } private val dataClient = this.client.newBuilder()
and add a separate cache. The data is currently 4.5MB gzipped, so you can set a 10MB limit.
extensions-source/lib-multisrc/kemono/src/eu/kanade/tachiyomi/multisrc/kemono/Kemono.kt
Lines 55 to 60 in 92ab8f0
.cache( Cache( directory = File(Injekt.get<Application>().externalCacheDir, "network_cache_${name.lowercase()}"), maxSize = 50L * 1024 * 1024, // 50 MiB ), ) - This
dataClient
should also useaddNetworkInterceptor
to rewrite the response. Remove these headers:Cache-Control
,Expires
,Pragma
. - Finally, make the request with
dataClient
with the expiration period as you wish:
extensions-source/lib-multisrc/kemono/src/eu/kanade/tachiyomi/multisrc/kemono/Kemono.kt
Lines 152 to 156 in 92ab8f0
val request = GET( "$baseUrl/$apiPath/creators", headers, CacheControl.Builder().maxStale(30, TimeUnit.MINUTES).build(), ) - Remember to enable logging in the app's advanced settings and verify the cache is working. Enter the browse page multiple times to see if only the first request is sent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make fields private
wherever possible.
private fun tryCompatibility(manga: SManga): SManga { | ||
val substring = mangaSubStrings.first { manga.url.contains(it, ignoreCase = true) } | ||
val slug = manga.url | ||
.substringAfterLast("$substring/") | ||
.substringBeforeLast("/") | ||
return database.values.firstOrNull { it.slug == slug } | ||
?.toSManga() | ||
?: throw IOException("Migrate a obra para a $name") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your code suggests the URL format has changed to using an ID. You should bump the versionId
to force users to migrate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's also preferred to clear the old preferences:
extensions-source/src/zh/sixmh/src/eu/kanade/tachiyomi/extension/zh/sixmh/SixMH.kt
Lines 21 to 26 in 572201d
init { | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | |
// Delete old preferences for "6漫画/zh/1" | |
Injekt.get<Application>().deleteSharedPreferences("source_7259486566651312186") | |
} | |
} |
Closes #10149
Checklist:
extVersionCode
value inbuild.gradle
for individual extensionsoverrideVersionCode
orbaseVersionCode
as needed for all multisrc extensionsisNsfw = true
flag inbuild.gradle
when appropriateid
if a source's name or language were changedweb_hi_res_512.png
when adding a new extension