Fix pages cache usage

(cherry picked from commit 9e2b60e15e)
This commit is contained in:
Koitharu
2025-01-09 08:26:43 +02:00
parent b3f748c000
commit eb1eee1681

View File

@@ -185,11 +185,8 @@ class PageLoader @Inject constructor(
prefetchLock.withLock {
while (prefetchQueue.isNotEmpty()) {
val page = prefetchQueue.pollFirst() ?: return@launch
if (cache.get(page.url) == null) { // FIXME use pageUrl
synchronized(tasks) {
tasks[page.id] = loadPageAsyncImpl(page, skipCache = false, isPrefetch = true)
}
return@launch
synchronized(tasks) {
tasks[page.id] = loadPageAsyncImpl(page, skipCache = false, isPrefetch = true)
}
}
}
@@ -202,13 +199,14 @@ class PageLoader @Inject constructor(
): ProgressDeferred<Uri, Float> {
val progress = MutableStateFlow(PROGRESS_UNDEFINED)
val deferred = loaderScope.async {
if (!skipCache) {
// FIXME use pageUrl
cache.get(page.url)?.let { return@async it.toUri() }
}
counter.incrementAndGet()
try {
loadPageImpl(page, progress, isPrefetch)
loadPageImpl(
page = page,
progress = progress,
isPrefetch = isPrefetch,
skipCache = skipCache,
)
} finally {
if (counter.decrementAndGet() == 0) {
onIdle()
@@ -232,9 +230,13 @@ class PageLoader @Inject constructor(
page: MangaPage,
progress: MutableStateFlow<Float>,
isPrefetch: Boolean,
skipCache: Boolean,
): Uri = semaphore.withPermit {
val pageUrl = getPageUrl(page)
check(pageUrl.isNotBlank()) { "Cannot obtain full image url for $page" }
if (!skipCache) {
cache.get(pageUrl)?.let { return it.toUri() }
}
val uri = Uri.parse(pageUrl)
return when {
uri.isZipUri() -> if (uri.scheme == URI_SCHEME_ZIP) {